Management & CommerceVery hardBusiness analyst · SQL test
Table emp has ids 1–6. Table blocked(id) has two rows: 2 and NULL. What do these return? P: SELECT COUNT(*) FROM emp WHERE id NOT IN (SELECT id FROM blocked); Q: SELECT COUNT(*) FROM emp e WHERE NOT EXISTS (SELECT 1 FROM blocked b WHERE b.id = e.id);
- A. P = 0, Q = 5
- B. P = 5, Q = 5
- C. P = 0, Q = 0
- D. P = 5, Q = 6
Correct answer: A. P = 0, Q = 5
For id NOT IN (2, NULL), every comparison with NULL is unknown, so the condition is never true and P returns 0. NOT EXISTS only checks for matching rows, so it excludes id 2 and returns 5. This is why NOT EXISTS is safer when the subquery can contain NULLs.
Practise more Operations, Supply Chain & Business Analytics questionsOperations, Supply Chain & Business Analytics: notes and key points
More Operations, Supply Chain & Business Analytics questions
- Table emp(id, name, dept, salary, mgr) has rows (1, Asha, Sales, 90, NULL), (2, Ravi, Sales, 60, 1), (3, Meena, Sales, 75, 1), (4, Kiran…
- Table emp(id, name, dept, salary, mgr) has rows (1, Asha, Sales, 90, NULL), (2, Ravi, Sales, 60, 1), (3, Meena, Sales, 75, 1), (4, Kiran…
- Table emp(id, name, dept, salary, mgr) has rows (1, Asha, Sales, 90, NULL), (2, Ravi, Sales, 60, 1), (3, Meena, Sales, 75, 1), (4, Kiran…
- Table emp(id, name, dept, salary, mgr) has rows (1, Asha, Sales, 90, NULL), (2, Ravi, Sales, 60, 1), (3, Meena, Sales, 75, 1), (4, Kiran…
- orders(oid, cust, amount) has rows (1, A, 100), (2, A, 200), (3, B, 300). items(oid, sku) lists the products in each order: order 1 has 2…
- Order 1 contains SKUs x and y; order 3 contains SKUs x, y and z. Query P combines the SKU lists of the two orders with UNION; query Q uses…