Question discussion

What is the output of the following SQL statements?CREATE TABLE emp(id INT, name TEXT, mgr INT); INSERT INTO emp VALUES (1,'A',NULL),(2,'B'…

2332Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following SQL statements?

CREATE TABLE emp(id INT, name TEXT, mgr INT);
INSERT INTO emp VALUES (1,'A',NULL),(2,'B',1),(3,'C',1),(4,'D',2),(5,'E',2),(6,'F',3),(7,'G',2);
SELECT COUNT(*) FROM emp x JOIN emp y ON x.mgr = y.mgr AND x.id < y.id;
  • A8
  • B3
  • C4
  • D5
Correct answer: C

Explanation

The self-join pairs employees with the same non-null manager once each: manager 1 gives 1 pair, manager 2 (D, E, G) gives 3 pairs and manager 3 gives none, so the total is 4.

Discussion 0

Nobody has replied yet. Start the discussion!