Which values does the nested query with EXCEPT return?
An analyst is combining values from two tables into a set. The SQL uses several set difference operations, including one inside a subquery in FROM. Examine the query and the rows in iv_t1 and iv_t2. Which values of x remain in the result?
Predict the resultSubqueries, CTEs, EXISTS / IN, UNIONJuniorAnalystBackendQA
Input data · iv_t1
| x |
|---|
| 1 |
| 1 |
| 2 |
| NULL |
Input data · iv_t2
| x |
|---|
| 1 |
| 2 |
| 2 |
| 3 |
| NULL |
Query
SELECT x
FROM (
SELECT x
FROM iv_t2
WHERE x IS NOT NULL
EXCEPT DISTINCT
SELECT x
FROM (
SELECT x
FROM iv_t1
WHERE x IS NOT NULL
EXCEPT DISTINCT
SELECT x
FROM iv_t1
WHERE x = 1
) AS right_set
) AS result_set
ORDER BY x