GATE DA 2026 | Question 51

Database Management and Warehousing › SQL · MSQ · 2 marks · Answer: A

  1. Question 51Database Management and Warehousingmsq2 marks
    Consider a table Employee(EmpID, TeamID), where the column EmpID (ID of an employee) is the primary key. The column TeamID denotes the team ID of the team of which the employee is a member. TeamID is a NOT NULL column. We want to display the size of the team (denoted as TeamSize) in which each employee is a member by using SQL. As an example, the desired output for the given Employee table is also shown in tabular form.
    Employee              Output
    EmpID  TeamID         EmpID  TeamSize
    1      8              1      3
    2      8              2      3
    3      8              3      3
    4      7              4      2
    5      7              5      2
    6      9              6      1
    Which of the following is/are correct?
    • A.
      sql
      SELECT E.EmpID, B.TeamSize FROM Employee AS E, (SELECT TeamID, COUNT(TeamID) AS TeamSize FROM Employee GROUP BY TeamID) AS B WHERE E.TeamID = B.TeamID
      ✓
    • B.
      sql
      SELECT A.EmpID, COUNT(B.TeamID) AS TeamSize FROM Employee AS A, Employee AS B WHERE A.TeamID = B.TeamID AND A.EmpID = B.EmpID GROUP BY A.EmpID
    • C.
      sql
      SELECT B.EmpID, B.TeamSize FROM (SELECT EmpID, COUNT(TeamID) AS TeamSize FROM Employee GROUP BY EmpID) AS B
    • D.
      sql
      SELECT A.EmpID, B.TeamSize FROM Employee AS A, (SELECT COUNT(TeamID) AS TeamSize FROM Employee GROUP BY TeamID) AS B WHERE A.TeamID = B.TeamID

    Answer: A

    Solution

    - (A) The subquery gives (TeamID, size) for each team. Joining each employee to their team's row gives the size. Correct. - (B) The condition A.EmpID = B.EmpID pairs each employee only with itself, so every count is 1. Wrong. - (C) Grouping by EmpID (the primary key) puts each employee in a group of size 1. Wrong. - (D) The derived table B has no TeamID column, so B.TeamID is invalid. Wrong. Answer: (A).

More GATE PYQ on SQL

All GATE DA Database Management and Warehousing PYQ →

Attempt GATE DA 2026 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →