1Z0-047 · Question #240
View the Exhibit and examine DEPARTMENTS and the LOCATIONS tables. Evaluate the following SOL statement: SELECT location_id, city FROM locations I WHERE NOT EXISTS (SELECT location_id FROM…
The correct answer is C. The statement would execute but it will return zero rows because the WHERE clause in the inner query. See the full explanation below for the reasoning.
Question
View the Exhibit and examine DEPARTMENTS and the LOCATIONS tables. Evaluate the following SOL statement:
SELECT location_id, city FROM locations I WHERE NOT EXISTS (SELECT location_id FROM departments WHERE location_id <> I. location_id); This statement was written to display LOCATION_ID and CITY where there are no departments located. Which statement is true regarding the execution and output of the command?
Exhibit
Options
- AThe statement would execute and would return the desired results.
- BThe statement would not execute because the = comparison operator is missing in the WHERE clause
- CThe statement would execute but it will return zero rows because the WHERE clause in the inner query
- DThe statement would not execute because the WHERE clause in the outer query is missing the column
How the community answered
(69 responses)- A10% (7)
- B3% (2)
- C81% (56)
- D6% (4)
Community Discussion
2C is your pick here, but the real trap is that <> trick in the subquery. NOT EXISTS with a <> condition in the inner WHERE means the subquery returns rows for almost every location (because some department will always have a different location_id), so NOT EXISTS evaluates to FALSE across the board and you get zero rows back, which is exactly what C says.
Exactly right, and the corollary worth burning into your head is that NOT EXISTS paired with equality works fine here, it is only when someone flips it to the inequality that the subquery explodes into almost-always-returning-rows territory, which is the same mental model error that causes people to confuse NOT IN null-trap behavior with NOT EXISTS null-safety, two separate landmines on the same stretch of road.
