CS FundamentalsHardWipro · Cognizant technical pattern
Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen', 'Delhi', 700), (5, 'Dia', NULL, 200), (6, 'Ben', 'Delhi', 700). What does this query return?
Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen', 'Delhi', 700), (5, 'Dia', NULL, 200), (6, 'Ben', 'Delhi', 700).
What does this query return?
SELECT COUNT(*) FROM Orders WHERE amount > 250 OR amount <= 250;
- A. 6
- B. 4
- C. 0
- D. 5
Correct answer: D. 5
The condition looks like a tautology, but for row 2 (amount NULL) both comparisons are UNKNOWN, and UNKNOWN OR UNKNOWN is UNKNOWN, so the row is filtered out. 5 rows remain. 6 assumes two-valued logic.
More DBMS and SQL questions
- Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen'…
- R(A, B, C, D) has FDs A → B and C → D. It is decomposed into R1(A, B), R2(C, D) and R3(A, C). Which statement is correct?
- R(A, B, C, D) has exactly two candidate keys: A and BC. How many superkeys does R have?
- You need the customers who have placed no orders. Orders.cust may contain NULL values. Which query is correct in that case?
- Table Proj(pid, lead, dept, budget, parent) rows: (1, 'Uma', 'R&D', 900, NULL), (2, 'Vik', 'R&D', 400, 1), (3, 'Uma', 'Ops', NULL, 1), (4…
- Table Proj(pid, lead, dept, budget, parent) rows: (1, 'Uma', 'R&D', 900, NULL), (2, 'Vik', 'R&D', 400, 1), (3, 'Uma', 'Ops', NULL, 1), (4…