Which operator removes duplicates when combining results from two SELECT statements?

Study for the SQL Basics Test. Improve your knowledge with multiple choice questions and detailed explanations. Prepare effectively to master SQL concepts!

Multiple Choice

Which operator removes duplicates when combining results from two SELECT statements?

Explanation:
When you want to combine results from two SELECT statements into one result set, you use a set operation. The operator that removes duplicates in the merged results is UNION. It returns all distinct rows from both queries, so any duplicate row that appears in either result appears only once in the final output. If you needed to keep duplicates, you’d use UNION ALL, which simply appends the two results together without eliminating duplicates. By comparison, INTERSECT gives you only the rows that appear in both results, and CROSS JOIN creates every possible pairing of rows from the two results, not a deduplicated merge. For example, if the two queries return 1, 2, 3 and 2, 3, 4, UNION produces 1, 2, 3, 4; UNION ALL produces 1, 2, 3, 2, 3, 4; INTERSECT produces 2, 3.

When you want to combine results from two SELECT statements into one result set, you use a set operation. The operator that removes duplicates in the merged results is UNION. It returns all distinct rows from both queries, so any duplicate row that appears in either result appears only once in the final output. If you needed to keep duplicates, you’d use UNION ALL, which simply appends the two results together without eliminating duplicates. By comparison, INTERSECT gives you only the rows that appear in both results, and CROSS JOIN creates every possible pairing of rows from the two results, not a deduplicated merge. For example, if the two queries return 1, 2, 3 and 2, 3, 4, UNION produces 1, 2, 3, 4; UNION ALL produces 1, 2, 3, 2, 3, 4; INTERSECT produces 2, 3.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy