Which set operation returns only the rows that are in the first query but not in the second?

Study for the Database Systems Test. Prepare with flashcards and multiple choice questions, each with hints and explanations. Get ready for success!

Multiple Choice

Which set operation returns only the rows that are in the first query but not in the second?

Explanation:
EXCEPT isolates the difference between two query results: it returns rows that appear in the first result but not in the second. This is exactly what you want when you need items that exist in the first set minus anything that also appears in the second. For example, if you list IDs of orders that are pending and subtract the IDs of orders that have been shipped, you’ll get the pending orders that haven’t yet shipped. In standard behavior, duplicates are removed from the result, though some databases offer EXCEPT ALL to preserve duplicates if needed. The other operations do different things: UNION merges results from both queries, INTERSECT returns only rows that appear in both, and UNION ALL merges results including duplicates. Therefore, the operation described is EXCEPT.

EXCEPT isolates the difference between two query results: it returns rows that appear in the first result but not in the second. This is exactly what you want when you need items that exist in the first set minus anything that also appears in the second. For example, if you list IDs of orders that are pending and subtract the IDs of orders that have been shipped, you’ll get the pending orders that haven’t yet shipped. In standard behavior, duplicates are removed from the result, though some databases offer EXCEPT ALL to preserve duplicates if needed. The other operations do different things: UNION merges results from both queries, INTERSECT returns only rows that appear in both, and UNION ALL merges results including duplicates. Therefore, the operation described is EXCEPT.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy