91.9k views
3 votes
Define UNION, MINUS, UNION ALL, and INTERSECT in SQL.

a) UNION combines result sets and removes duplicates; MINUS finds differences; UNION ALL combines all results; INTERSECT finds common rows.
b) UNION finds common rows; MINUS combines result sets and removes duplicates; UNION ALL combines all results; INTERSECT finds differences.
c) UNION combines result sets and keeps duplicates; MINUS finds common rows; UNION ALL combines all results; INTERSECT removes duplicates.
d) UNION finds common rows; MINUS combines result sets and removes duplicates; UNION ALL combines all results; INTERSECT finds differences.

User Dave Kerr
by
7.9k points

1 Answer

1 vote

Final answer:

The UNION, MINUS, UNION ALL, and INTERSECT operators in SQL have different functionalities. UNION combines result sets and removes duplicates, MINUS finds differences, UNION ALL combines all results, and INTERSECT finds common rows.

Step-by-step explanation:

In SQL, the UNION operator combines the result sets of two or more SELECT statements and removes duplicate rows. For example, if you have two tables with some common rows, the UNION operator will combine those common rows into a single result set.

The MINUS operator, also known as the EXCEPT operator in some databases, finds the difference between two result sets. It returns only the rows that are present in the first SELECT statement but not in the second SELECT statement.

The UNION ALL operator, on the other hand, combines all the result sets of two or more SELECT statements without removing any duplicate rows. This means that if there are duplicate rows in the result sets, they will be included in the final result.

The INTERSECT operator finds the common rows between two result sets. It returns only the rows that are present in both SELECT statements and removes any duplicate rows that may exist.

User MotherDawg
by
7.7k points