CS FundamentalsHardGATE CS · TCS NQT
DEPT(d, name) has rows (10,A), (20,B), (30,C), (40,D) and EMP(id, dept) has 3 employees in dept 10, 2 in dept 20, 1 in dept 30 and none in dept 40. How many rows does this query return? SELECT name FROM DEPT LEFT JOIN EMP ON EMP.dept = DEPT.d GROUP BY name HAVING COUNT(*) = 1;
- A. 1
- B. 2
- C. 3
- D. 0
Correct answer: B. 2
The left join keeps dept D with a single NULL-extended row, so COUNT(*) is 1 for both C (one real employee) and D (no employee). The result has 2 rows; COUNT(EMP.id) would have counted only C.
More DBMS and SQL questions
- EMP has salaries 300, 200, 200, 200, 150, 100 for six employees. Let QR select employees whose RANK() OVER (ORDER BY sal DESC) equals 3…
- R(A, B, C, D, E) has the functional dependencies A → B, BC → D, D → E and E → A. The number of candidate keys of R and its highest normal…
- Consider the schedule S: r1(A) r3(B) r2(C) w2(A) r4(C) w4(B) r1(D) r3(D), where ri/wi is a read/write by transaction Ti. How many distinct…
- A B+ tree on 8-byte keys uses 4096-byte blocks. An internal node holds p tree pointers (8 bytes each) and p − 1 keys. A leaf holds q (key…
- E(id, dept) = (1, 10), (2, 10), (3, 20), (4, 30), (5, NULL), (6, 20), (7, 40) and D(did, loc) = (10, X), (20, Y), (20, X), (30, Y), (50…
- S(v) holds the nine rows 10, 20, 20, 30, 30, 30, 40, 40, 50. The query SELECT SUM(v) OVER (ORDER BY v) FROM S uses the default frame. What…