Difference between Union, Union all, INTERSECT and MINUS


Difference between Union,Union all,INTERSECT and MINUS

  1. UNION
    1. 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.
  2. UNION ALL
    1. UNION ALL show all records including duplicate
  3. INTERSECT
    1. 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.)
  4. MINUS
    1. 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)

Union, Union all, INTERSECT and 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