SQL · Databases
43 questions · asked in 23 of 27 years (2000–2026)
MCQ 34 · MSQ 1 · NAT 81-mark 26 · 2-mark 17
2000Questions per year2026
Questions 6–10 of 43
Consider a relational database containing the following schemas.
The primary key of each table is indicated by underlining the constituent fields.
The number of rows returned by the above SQL query is
The primary key of each table is indicated by underlining the constituent fields.
SELECT s.sno, s.sname
FROM Suppliers s, Catalogue c
WHERE s.sno=c.sno AND
cost > (SELECT AVG (cost)
FROM Catalogue
WHERE pno = 'P4'
GROUP BY pno) ;The number of rows returned by the above SQL query is
Answer: (A)
Subquery: only the P4 rows are used, at cost 200 (S2) and 250 (S3). Their average is . GROUP BY pno gives a single group, so the subquery returns one value.
The Catalogue rows with cost 225 are (S2, P5, 250), (S3, P1, 250), (S3, P5, 300) and (S3, P4, 250). That is 4 rows.
The join s.sno = c.sno matches each of these rows to exactly one supplier, because sno is the key of Suppliers. The query has no DISTINCT, so the supplier S3 is listed three times and S2 once. The query returns 4 rows.
Answer: (A)
The Catalogue rows with cost 225 are (S2, P5, 250), (S3, P1, 250), (S3, P5, 300) and (S3, P4, 250). That is 4 rows.
The join s.sno = c.sno matches each of these rows to exactly one supplier, because sno is the key of Suppliers. The query has no DISTINCT, so the supplier S3 is listed three times and S2 once. The query returns 4 rows.
Answer: (A)
A relational database contains two tables Student and Performance as shown below:
The primary key of the Student table is Roll_no. For the Performance table, the columns Roll_no. and Subject_code together from the primary key. Consider the SQL query given below:
The primary key of the Student table is Roll_no. For the Performance table, the columns Roll_no. and Subject_code together from the primary key. Consider the SQL query given below:
SELECT S.Student_name, sum(P.Marks)
FROM Student S, Performance P
WHERE P.Marks > 84
GROUP BY S.Student_name;The number of rows returned by the above SQL query is _________ . Answer: 5
The query has no join condition. So FROM gives a cross product, and each student is paired with every row of Performance.
The WHERE condition Marks 84 keeps 5 rows of Performance, with marks 86, 95, 90, 89 and 92. Each of these rows is paired with all 5 students.
GROUP BY Student_name makes one row for each student name 5 rows.
Answer: 5
The WHERE condition Marks 84 keeps 5 rows of Performance, with marks 86, 95, 90, 89 and 92. Each of these rows is paired with all 5 students.
GROUP BY Student_name makes one row for each student name 5 rows.
Answer: 5
Consider the following two tables and four queries in SQL.
Book (isbn, bname), Stock (isbn, copies)
Which one of the queries above is certain to have an output that is a superset of the outputs of the other three queries?
Book (isbn, bname), Stock (isbn, copies)
Query 1: SELECT B.isbn, S.copies
FROM Book B INNER JOIN Stock S
ON B.isbn = S.isbn;
Query 2: SELECT B.isbn, S.copies
FROM Book B LEFT OUTER JOIN Stock S
ON B.isbn = S.isbn;
Query 3: SELECT B.isbn, S.copies
FROM Book B RIGHT OUTER JOIN Stock S
ON B.isbn = S.isbn;
Query 4: SELECT B.isbn, S.copies
FROM Book B FULL OUTER JOIN Stock S
ON B.isbn = S.isbn; Which one of the queries above is certain to have an output that is a superset of the outputs of the other three queries?
Answer: (D)
Let us look at each query:
- Query 1 (inner join): gives only the matching rows.
- Query 2 (left outer): gives the matching rows and the Book rows with no match.
- Query 3 (right outer): gives the matching rows and the Stock rows with no match.
- Query 4 (full outer): gives the matching rows and the unmatched rows of both tables, so it always holds the other three.
Answer: Query 4
- Query 1 (inner join): gives only the matching rows.
- Query 2 (left outer): gives the matching rows and the Book rows with no match.
- Query 3 (right outer): gives the matching rows and the Stock rows with no match.
- Query 4 (full outer): gives the matching rows and the unmatched rows of both tables, so it always holds the other three.
Answer: Query 4
Consider a database that has the relation schema EMP (EmpId, EmpName, and DeptName). An instance of the schema EMP and a SQL query on it are given below.
| EMP | ||
| EmpId | EmpName | DeptName |
| 1 | XYA | AA |
| 2 | XYB | AA |
| 3 | XYC | AA |
| 4 | XYD | AA |
| 5 | XYE | AB |
| 6 | XYF | AB |
| 7 | XYG | AB |
| 8 | XYH | AC |
| 9 | XYI | AC |
| 10 | XYJ | AC |
| 11 | XYK | AD |
| 12 | XYL | AD |
| 13 | XYM | AE |
SELECT AVG(EC.Num)
FROM EC
WHERE (DeptName, Num) IN
(SELECT DeptName, COUNT(EmpId) AS
EC(DeptName, Num)
FROM EMP
GROUP BY DeptName) The output of executing the SQL query is _____.Answer: 2.6
The inner query groups the rows by department and counts the employees in each. The counts are AA 4, AB 3, AC 3, AD 2 and AE 1. Each (DeptName, Num) pair comes from this same result, so all five rows pass the condition.
The average is (4 + 3 + 3 + 2 + 1) / 5 = 13 / 5 = 2.6
Answer: 2.6
The average is (4 + 3 + 3 + 2 + 1) / 5 = 13 / 5 = 2.6
Answer: 2.6
Consider the following database table named top_scorer.
Consider the following SQL query:
The number of tuples returned by the above SQL query is ___________.
Consider the following SQL query:
SELECT ta.player FROM top_scorer AS ta
WHERE ta.goals >ALL (SELECT tb.goals
FROM top_scorer AS tb
WHERE tb.country = 'Spain')
AND ta.goals >ANY (SELECT tc.goals
FROM top_scorer AS tc
WHERE tc.country = 'Germany') The number of tuples returned by the above SQL query is ___________.
Answer: 7
Check each condition one by one:
- No player is from Spain. So the condition " ALL (empty set)" is true for every player.
- The condition " ANY (German goals: 16, 14, 11, 10, 10)" means goals 10, the smallest value.
Players with more than 10 goals are Klose, Ronaldo, G Müller, Fontaine, Pelé, Klinsmann and Kocsis. That makes 7 players.
Answer: 7
- No player is from Spain. So the condition " ALL (empty set)" is true for every player.
- The condition " ANY (German goals: 16, 14, 11, 10, 10)" means goals 10, the smallest value.
Players with more than 10 goals are Klose, Ronaldo, G Müller, Fontaine, Pelé, Klinsmann and Kocsis. That makes 7 players.
Answer: 7
Keep practising