CS FundamentalsHardProduct-company MCQ pattern
Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2), (4, 'John', 'Sales', 40000, 1), (5, 'Kiran', 'IT', 90000, 2), (6, 'Dev', NULL, 45000, 4), (7, 'Lata', 'Sales', NULL, 4). Table Dept(dname, city) rows: ('HR', 'Pune'), ('IT', 'Delhi'), ('Ops', 'Mumbai'). What does this query return (SQL standard behaviour, as in PostgreSQL and SQLite)?
Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2), (4, 'John', 'Sales', 40000, 1), (5, 'Kiran', 'IT', 90000, 2), (6, 'Dev', NULL, 45000, 4), (7, 'Lata', 'Sales', NULL, 4).
Table Dept(dname, city) rows: ('HR', 'Pune'), ('IT', 'Delhi'), ('Ops', 'Mumbai').
What does this query return (SQL standard behaviour, as in PostgreSQL and SQLite)?
SELECT dept FROM Emp EXCEPT SELECT dname FROM Dept;
- A. Sales, Sales and NULL
- B. Sales and NULL
- C. No rows
- D. Sales
Correct answer: B. Sales and NULL
EXCEPT works on distinct rows and, unlike WHERE comparisons, treats NULLs as equal to each other. Emp's distinct depts {NULL, HR, IT, Sales} minus {HR, IT, Ops} = {NULL, Sales}. Duplicates are removed, so Sales appears once.
More DBMS and SQL questions
- Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2)…
- Table Enroll(sid, cid) rows: (1, 'C1'), (1, 'C2'), (2, 'C1'), (3, 'C1'), (3, 'C2'), (3, 'C3'), (4, 'C3'). Table Course(cid) rows: ('C1')…
- R(A, B, C, D, E) has FDs A → B, B → C, C → A, D → E. How many candidate keys does R have, and what is its highest normal form?
- R(A, B, C, D, E, F) has FDs AB → C, C → D, D → B, E → F. Which statement is correct?
- R(A, B, C, D) has FDs AB → CD, C → A, D → B. How many candidate keys does R have, and what is its highest normal form?
- R(A, B, C, D) has FDs AB → CD, C → A, D → B, giving candidate keys AB, AD, BC and CD. How many superkeys does R have?