UNION, UNION ALL, INTERSECT AND EXCEPT
UNION: We can combine two or more query results of different tables using UNION and it will show all the distinct results.
SELECT * FROM TableName1
UNION
SELECT * FROM TableName2
# This will display all the different rows from Table1 and Table2
UNION ALL: This can also combine the results of two or more queries and displays all the results together with the repeating rows.
SELECT * FROM TableName1
UNION ALL
SELECT * FROM TableName2
# This will display all the rows of Table1 and Table2
INTERSECT: This operator shows the common rows from the results of two or more queries.
SELECT * FROM TableName1
INTERSECT
SELECT * FROM TableName2
# This will display all the rows that are common in Table1 and Table2
EXCEPT: This operator shows the results of one table and not in the other table.
SELECT * FROM TableName1
EXCEPT
SELECT * FROM TableName2
# This will display all the rows from Table1 and not in Table2
UNION: We can combine two or more query results of different tables using UNION and it will show all the distinct results.
SELECT * FROM TableName1
UNION
SELECT * FROM TableName2
# This will display all the different rows from Table1 and Table2
UNION ALL: This can also combine the results of two or more queries and displays all the results together with the repeating rows.
SELECT * FROM TableName1
UNION ALL
SELECT * FROM TableName2
# This will display all the rows of Table1 and Table2
INTERSECT: This operator shows the common rows from the results of two or more queries.
SELECT * FROM TableName1
INTERSECT
SELECT * FROM TableName2
# This will display all the rows that are common in Table1 and Table2
EXCEPT: This operator shows the results of one table and not in the other table.
SELECT * FROM TableName1
EXCEPT
SELECT * FROM TableName2
# This will display all the rows from Table1 and not in Table2
No comments:
Post a Comment