CS FundamentalsModerateTCS NQT · Infosys 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?
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?
SELECT COUNT(*), COUNT(dept), COUNT(DISTINCT dept) FROM Emp;
- A. 6, 6, 3
- B. 7, 6, 4
- C. 7, 6, 3
- D. 7, 7, 4
Correct answer: C. 7, 6, 3
COUNT(*) counts all 7 rows. COUNT(dept) skips Dev's NULL: 6. COUNT(DISTINCT dept) counts HR, IT, Sales = 3; NULL is not counted as a distinct value.
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)…
- 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)…