SQL · Database Management and Warehousing
4 questions · asked in 3 of 3 years (2024–2026)
MSQ 1 · NAT 31-mark 2 · 2-mark 2
2024Questions per year2026
Questions 1–4 of 4
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.
Which of the following is/are correct?
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.
Which of the following is/are correct?
One or more options are correct.
Answer: (A)
The team size is found by grouping on . Each employee row is then joined back to the size of its own team using .
(A) is correct. The subquery , , gives one row per team with its size, and keeps the column. Joining with on gives each employee the size of their own team. For the sample table it gives 3, 3, 3, 2, 2, 1.
(B) is wrong. It joins and on as well. Since is the primary key, each employee matches only their own row, so every is 1.
(C) is wrong. It groups by , which is unique, so every count is 1.
(D) is wrong. Its subquery returns only , with no column, so the condition cannot be used. It is invalid SQL.
Answer: (A)
(A) is correct. The subquery , , gives one row per team with its size, and keeps the column. Joining with on gives each employee the size of their own team. For the sample table it gives 3, 3, 3, 2, 2, 1.
(B) is wrong. It joins and on as well. Since is the primary key, each employee matches only their own row, so every is 1.
(C) is wrong. It groups by , which is unique, so every count is 1.
(D) is wrong. Its subquery returns only , with no column, so the condition cannot be used. It is invalid SQL.
Answer: (A)
Let Account be a relation as shown.
Consider the given SQL query.
Consider the given SQL query.
SELECT AccNo FROM Account AS A
WHERE (SELECT COUNT(*) FROM Account AS B
WHERE A.Balance < B.Balance) >= (SELECT COUNT(*)
FROM Account AS C WHERE A.Balance > C.Balance) The number of rows returned by the SQL query is ________. (Answer in integer)Answer: 3
Take each account . The query tests whether the number of accounts with a strictly higher balance is the number with a strictly lower balance. Balances: .
Accounts that pass: , so rows.
Answer: 3
Accounts that pass: , so rows.
Answer: 3
On a relation named Loan of a bank:
The following SQL query is executed:
The number of rows returned by the query is _______(Answer in integer)
The following SQL query is executed:
SELECT L1.loan number
FROM Loan L1
WHERE L1.amount >(SELECT MAX(L2.amount)
FROM Loan L2
WHERE L2.branch name='SR Nagar'); The number of rows returned by the query is _______(Answer in integer)
Answer: 3
Inner subquery: it finds where . The SR Nagar loans are , and . So the maximum .
Outer query: it picks the loans with (strictly greater). Checking each loan: ✓, , , , ✓, ✓, .
Loans that qualify: . This gives rows.
Answer: 3
Outer query: it picks the loans with (strictly greater). Checking each loan: ✓, , , , ✓, ✓, .
Loans that qualify: . This gives rows.
Answer: 3
Consider the following two tables named Raider and Team in a relational database maintained by a Kabaddi league. The attribute ID in table Team references the primary key of the Raider table, ID.
The SQL query described below is executed on this database:
The SQL query described below is executed on this database:
SELECT *
FROM Raider, Team
WHERE Raider.ID=Team.ID AND City=“Jaipur” AND
RaidPoints > 200; The number of rows returned by this query is _________ .Answer: 3
| ID | Name | Raid | Raid Point | City | Bid Point |
| 1 | ARJUN | 200 | 250 | JAIPUR | 250 |
| 2 | ANKUSH | 190 | 219 | JAIPUR | 200 |
| 3 | SUNIL | 150 | 200 | PATNA | 195 |
| 4 | REZA | 150 | 190 | PATNA | 200 |
| 5 | PRATHAM | 175 | 220 | HYDERABAD | 175 |
| 6 | GOPAL | 193 | 215 | JAIPUR | 200 |
This table is the result of the join condition
In this table, keep only the rows where Raid Point is This gives four tuples.
| ID | Name | Raid | Raid Point | City | Bid Point |
| 1 | ARJUN | 200 | 250 | JAIPUR | 250 |
| 2 | ANKUSH | 190 | 219 | JAIPUR | 200 |
| 5 | PRATHAM | 175 | 220 | HYDERABAD | 175 |
| 6 | GOPAL | 193 | 215 | JAIPUR | 200 |
Now, from this table, keep only the tuples whose city is "JAIPUR". We get:
| ID | Name | Raid | Raid Point | City | Bid Point |
| 1 | ARJUN | 200 | 250 | JAIPUR | 250 |
| 2 | ANKUSH | 190 | 219 | JAIPUR | 200 |
| 6 | GOPAL | 193 | 215 | JAIPUR | 200 |
So the SQL query returns three tuples as output.
Keep practising