CS FundamentalsModerateWipro · Cognizant 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 e.name, d.city FROM Emp e INNER JOIN Dept d ON e.dept = d.dname;
- A. 7
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
Matches: Asha (HR) and Ravi, Meena, Kiran (IT) = 4. Sales has no row in Dept, Dev's NULL dept matches nothing, and Ops has no employees.
More DBMS and SQL questions
- Two tables have 6 rows and 4 rows. How many rows does SELECT FROM A, B; (no WHERE clause) return?
- A relation is in 2NF if it is in 1NF and:
- R(A, B, C, D) has functional dependencies A → B and B → C. What is the candidate key of R?
- Which statement about a clustered index is correct?
- Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2)…
- Transaction T2 reads a value that T1 has written but not yet committed; T1 later rolls back. What is this anomaly called?