UNION, INTERSECT & EXCEPT · Question 17 · Hard

UNION, INTERSECT & EXCEPT question 17

Table MayOrders:
order_id | coupon
1 | SAVE10
2 | NULL
3 | NULL

Table JuneOrders:
order_id | coupon
4 | NULL
5 | FEST20

Orders placed without a coupon have NULL in the coupon column. What does this query return?

SELECT COUNT(*)
FROM (SELECT coupon FROM MayOrders
      INTERSECT
      SELECT coupon FROM JuneOrders) t;
  1. 1
  2. 0
  3. 2
  4. 3
Answer and explanation

Answer: A. 1

Explanation: Set operators treat two NULLs as the same value, unlike the = operator in a WHERE clause. NULL is present on both sides, so INTERSECT returns a single NULL row; SAVE10 and FEST20 each appear on one side only.

Previous: Table Cricket: student Aman Bina Chetan Bina Table Football: student Bina… · Next: Table Cricket: student Aman Bina Chetan Bina Table Football: student Bina…

Practise union, intersect & except

Try a fresh set of union, intersect & except questions with an explanation after every answer, free and without signing up: UNION, INTERSECT & EXCEPT practice. Or sit a full placement mock test.

More union, intersect & except questions

More sql practice

Tables, Keys & Constraints · DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins · Aggregates & GROUP BY · Subqueries & CTEs · Window Functions · NULL Handling

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge