SQL
14 BEST SQL Books in 2021
SQL stands for Structured Query language, pronounced as "S-Q-L" or sometimes as "See-Quel." SQL is...
Unions combine the results from multiple SELECT queries into a consolidated result set.
The only requirements for this to work is that the number of columns should be the same from all the SELECT queries which needs to be combined .
Suppose we have two tables as follows
Let's now create a UNION query to combines both tables using DISTINCT
SELECT column1, column2 FROM `table1` UNION DISTINCT SELECT column1,column2 FROM `table2`;
Here duplicate rows are removed and only unique rows are returned.
SELECT `column1`,` column1` FROM `table1` UNION ALL SELECT ` column1`,` column1` FROM `table2`;
Here duplicate rows are included and since we use ALL.
Suppose there is a flaw in your database design and you are using two different tables meant for the same purpose. You want to consolidate these two tables into one while omitting any duplicate records from creeping into the new table. You can use UNION in such cases.In our myFlixDB lets combine
membership_number and full_names from Members table
with
movie_id and title from movies table
We can use the following query
SELECT `membership_number`,`full_names` FROM `members` UNION SELECT `movie_id`,`title` FROM `movies`;
Executing the above script in MySQL workbench against the myflixdb gives us the following results shown below.
SQL stands for Structured Query language, pronounced as "S-Q-L" or sometimes as "See-Quel." SQL is...
Data types in SQLite are different compared to other database management system. In SQLite, you...
What is Nested Blocks Oracle? In PL/SQL, each block can be nested into another block. They are...
SQL stands for Structured Query Language is a domain specific programming language for managing...
What is Identifiers? Identifiers are nothing but a name that is given to a PL/SQL object. The...
What is SQLite? SQLite is an open-source, embedded, relational database management system,...