CS FundamentalsHardAccenture · Capgemini 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). Table Customers(name, tier) rows: ('Ana', 'Gold'), ('Ben', 'Silver'), ('Eve', 'Gold'). What value does this query show for 'Eve'?
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).
Table Customers(name, tier) rows: ('Ana', 'Gold'), ('Ben', 'Silver'), ('Eve', 'Gold').
What value does this query show for 'Eve'?
SELECT c.name, COUNT(o.id) FROM Customers c LEFT JOIN Orders o ON c.name = o.cust GROUP BY c.name;
- A. 0
- B. 1
- C. NULL
- D. Eve does not appear
Correct answer: A. 0
The LEFT JOIN keeps Eve with NULLs in all Orders columns. COUNT(o.id) ignores that NULL, giving 0. COUNT(*) would have given 1, because it counts the padded row itself.
More DBMS and SQL questions
- R(A, B, C, D, E) has functional dependencies A → BC, CD → E and B → D. Which of the following is a candidate key?
- Account X holds 100. T1 reads X (100); T2 reads X (100); T1 writes X = 150 and commits; T2 writes X = 80 and commits. What is the final…
- Table Orders has a composite B-tree index on (city, amount). Which WHERE clause can use this index to narrow the search most effectively?
- Which of these queries is NOT valid in standard SQL?
- Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen'…
- Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen'…