Set Operations: general

SQL: SELECT: Joins and Sets

Set operations merge data in to one set based on column definitions and the data contained within each column.

The four set operations are:

  • UNION
  • UNION ALL
  • INTERSECT
  • EXCEPT

The number of columns need to match. If number of columns don't match it'll result in an error.

<query 1> <set operation> <query 2>
SELECT <column> FROM <table 1> <set operation> SELECT <column> FROM <table 2>;
SELECT <column>, <column> FROM <table 1> <set operation> SELECT <column>, <column> FROM <table 2>;