Difference between Union, Union all, INTERSECT and MINUS
Difference between Union,Union all,INTERSECT and MINUS
- UNION
- UNION is used to combine the results of two or more SELECT statements. However it will eliminate duplicate rows from its result set. In UNION number of columns and data type must be same in both the tables, on which UNION operation is being applied.
- UNION ALL
- UNION ALL show all records including duplicate
- INTERSECT
- Intersect operation is used to combine two SELECT statements, it retuns common records from both SELECT statements. In case of Intersect the number of columns and datatype must be same. (MySQL does not support INTERSECT operator.)
- MINUS
- The MINUS set operator will return results of two SELECT statements that are found in the first query specified that don’t exist in the second query. (MySQL Does not supports MINUS)
Related
find the nth highest salary in mysql without limit
How to find greater than average salary records in MySQL
how to find duplicate records in MySQL query
How to use second index forcefully in MySQL
How to get total number of rows in MySQL table with and without count