What are the set operators in SQL?

SQL queries which contain set operations are called compound queries.

Union, Union All, Intersect or Minus operators are the set operators used in the SQL.

In SQL, set operators are used to combine the results of two or more SELECT statements. The commonly used set operators are:

  1. UNION: Returns the combined result set of two or more SELECT statements, removing duplicate rows.
  2. UNION ALL: Similar to UNION, but it includes duplicate rows in the result set.
  3. INTERSECT: Returns the common rows between the result sets of two SELECT statements.
  4. EXCEPT (or MINUS in some databases): Returns the rows that are unique to the first SELECT statement and not present in the result set of the second SELECT statement.

These set operators allow you to perform operations on the sets of data retrieved by different SELECT statements.