CS FundamentalsVery hardAmazon/Flipkart SQL round · GATE CS
Table Stu(sid, sname) rows: (1, 'Om'), (2, 'Pia'), (3, 'Raj'), (4, 'Sia'). Table Takes(sid, cid, marks) rows: (1, 'C1', 80), (1, 'C2', NULL), (2, 'C1', 65), (3, 'C2', 90), (3, 'C3', 75), (5, 'C1', 50). What counts do Query 1 and Query 2 return?
Table Stu(sid, sname) rows: (1, 'Om'), (2, 'Pia'), (3, 'Raj'), (4, 'Sia').
Table Takes(sid, cid, marks) rows: (1, 'C1', 80), (1, 'C2', NULL), (2, 'C1', 65), (3, 'C2', 90), (3, 'C3', 75), (5, 'C1', 50).
What counts do Query 1 and Query 2 return?
-- Query 1 SELECT COUNT(*) FROM Stu s LEFT JOIN Takes t ON s.sid = t.sid WHERE t.marks >= 70; -- Query 2 SELECT COUNT(*) FROM Stu s LEFT JOIN Takes t ON s.sid = t.sid AND t.marks >= 70;
- A. 3 and 3
- B. 5 and 3
- C. 3 and 5
- D. 5 and 5
Correct answer: C. 3 and 5
In Query 1 the WHERE runs after the outer join and drops every row whose marks are NULL or < 70, leaving 3. In Query 2 the condition is part of ON: Om matches 1 row, Raj 2, and Pia and Sia each keep one NULL-padded row, so 5.
More DBMS and SQL questions
- Keys 7, 53, 17, 43, 38, 5, 27, 50, 47, 10 are inserted in this order into an empty B+ tree where a node holds at most 3 keys; an…
- Table Sale(id, rep, region, amt) rows: (1, 'Ira', 'N', 100), (2, 'Jai', 'S', 250), (3, 'Ira', 'S', NULL), (4, 'Kim', 'N', 300), (5, 'Jai'…
- R(A, B) has 8 tuples. What is the number of tuples in R ⋈ R (natural join of R with itself), and in R × ρ{S(C, D)}(R)?
- R(A, B, C, D, E, F) has FDs B → AC, E → F, EF → BD, F → E. Each option is a relation schema obtained by projecting R, with the…
- On R(A, B, C, D, E), F = {D → A, B → AE} and G = {BE → A, D → A, B → E}. Which statement is correct? ("F covers G" means every FD of G is…
- Table Sale(id, rep, region, amt) rows: (1, 'Ira', 'N', 100), (2, 'Jai', 'S', 250), (3, 'Ira', 'S', NULL), (4, 'Kim', 'N', 300), (5, 'Jai'…