CS FundamentalsHardProduct-company placement · GATE CS
Cust(cid, city) has rows (1, 'Pune'), (2, 'Delhi'), (3, NULL), (4, 'Pune'). Ord(oid, cid, amt) has rows (10, 1, 500), (11, 1, NULL), (12, 2, 300), (13, NULL, 200), (14, 5, 100). How many rows do these queries return? Q1: SELECT * FROM Cust c LEFT JOIN Ord o ON c.cid = o.cid AND o.amt > 250; Q2: SELECT * FROM Cust c LEFT JOIN Ord o ON c.cid = o.cid WHERE o.amt > 250;
- A. Q1 = 4, Q2 = 2
- B. Q1 = 2, Q2 = 2
- C. Q1 = 5, Q2 = 2
- D. Q1 = 4, Q2 = 4
Correct answer: A. Q1 = 4, Q2 = 2
In Q1 the amount test is part of the join, so every customer survives: 1 pairs with order 10, 2 with 12, and 3 and 4 get NULLs (4 rows). In Q2 the WHERE runs after the join and drops every row whose o.amt is NULL or small, leaving 2: a WHERE on the right table turns the outer join into an inner join.
More DBMS and SQL questions
- Ord(oid, cid, amt) has rows (10, 1, 500), (11, 1, NULL), (12, 2, 300), (13, NULL, 200), (14, 5, 100). What does SELECT COUNT()…
- Player(pid, team, runs) has rows (1, 'A', 50), (2, 'A', 70), (3, 'A', 70), (4, 'B', 40), (5, 'B', NULL), (6, 'B', 90), (7, 'C', NULL). For…
- Pay(d, amt) has rows (1, 10), (2, 20), (2, 30), (3, 40). For the row (2, 20), what value does SUM(amt) OVER (ORDER BY d) give?
- What does this query return? SELECT CASE NULL WHEN NULL THEN 'eq' ELSE 'ne' END, CASE WHEN NULL IS NULL THEN 'eq' ELSE 'ne' END;
- Skill(emp, sk) has rows (r, sql), (r, py), (r, go), (s, sql), (s, py), (t, sql), (t, go), (t, py), (t, c). Req(sk) has rows (sql), (py)…
- Emp(eid, name, mgr, sal) has rows (1, Kiran, NULL, 100), (2, Lata, 1, 80), (3, Mohan, 1, 120), (4, Neha, 2, 90), (5, Om, 4, 60), (6, Pari…