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'). How many rows does this query return?

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'). How many rows does this query return?
SELECT *
FROM Emp e FULL OUTER JOIN Dept d ON e.dept = d.dname;
  1. A. 8
  2. B. 7
  3. C. 4
  4. D. 5

Correct answer: A. 8

4 matched rows + 3 unmatched Emp rows (John, Lata, Dev) + 1 unmatched Dept row (Ops) = 8. 7 is what a LEFT JOIN returns (it drops Ops), 5 a RIGHT JOIN and 4 an INNER JOIN; NULL = NULL never matches, so Dev stays unmatched.

More DBMS and SQL questions

Exams that ask this topic