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 1–5 of 43
Consider the following database tables of a sports league.
player(pid,pname,age)
coach(cid,cname)
team(tid,tname,city,cid)
members(pid,tid)
An instance of the table and an SQL query are given.
The value returned by the given SQL query is _________. (Answer in integer)
player(pid,pname,age)
coach(cid,cname)
team(tid,tname,city,cid)
members(pid,tid)
An instance of the table and an SQL query are given.
|
|
|
|
SELECT MIN(P.age)
FROM player P
WHERE P.pid IN (
SELECT M.pid
FROM team T, coach C, members M
WHERE C.cname = 'Mark'
AND T.cid = C.cid
AND M.tid = T.tid
)The value returned by the given SQL query is _________. (Answer in integer)
Answer: 26
Table instances from the question:
: (1,Jasprit,31), (2,Atharva,24), (3,Ishan,26), (4,Axar,30)
: (101,Ricky), (102,Mark), (103,Trevor)
: (10,MI,Mumbai,102), (20,DC,Delhi,101), (30,PK,Mohali,103)
: (1,10), (2,30), (3,10), (4,20)
Solve the inner subquery first. The condition selects the coach . Next, selects the team . Next, selects the members with : and .
So the subquery gives . The outer query now finds among the players with . These are Jasprit (age ) and Ishan (age ).
.
Answer: 26
: (1,Jasprit,31), (2,Atharva,24), (3,Ishan,26), (4,Axar,30)
: (101,Ricky), (102,Mark), (103,Trevor)
: (10,MI,Mumbai,102), (20,DC,Delhi,101), (30,PK,Mohali,103)
: (1,10), (2,30), (3,10), (4,20)
Solve the inner subquery first. The condition selects the coach . Next, selects the team . Next, selects the members with : and .
So the subquery gives . The outer query now finds among the players with . These are Jasprit (age ) and Ishan (age ).
.
Answer: 26
Consider the following relational schema:
Which of the following options is/are correct SQL query/queries to retrieve the names of the students enrolled in course number (i.e. courseno) 1470?
Which of the following options is/are correct SQL query/queries to retrieve the names of the students enrolled in course number (i.e. courseno) 1470?
One or more options are correct.
Answer: (A), (C), (D)
A student qualifies when at least one Enrolled row has the same rollno and courseno 1470.
- (A) is correct. The correlated EXISTS is true exactly when such an Enrolled row exists.
- (B) is not correct. SIZEOF is not an SQL operator, so the query is not valid SQL.
- (C) is correct. COUNT(*) of the matching rows is more than 0 exactly when the same Enrolled row exists, so it gives the same students as EXISTS.
- (D) is correct. Students and Enrolled have only rollno in common, so NATURAL JOIN joins on rollno. The WHERE keeps courseno 1470. Since (rollno, courseno) is the key of Enrolled, each student has at most one such row, so no name is repeated.
Answer: (A), (C), (D)
- (A) is correct. The correlated EXISTS is true exactly when such an Enrolled row exists.
- (B) is not correct. SIZEOF is not an SQL operator, so the query is not valid SQL.
- (C) is correct. COUNT(*) of the matching rows is more than 0 exactly when the same Enrolled row exists, so it gives the same students as EXISTS.
- (D) is correct. Students and Enrolled have only rollno in common, so NATURAL JOIN joins on rollno. The WHERE keeps courseno 1470. Since (rollno, courseno) is the key of Enrolled, each student has at most one such row, so no name is repeated.
Answer: (A), (C), (D)
Consider the following table named Student in a relational database. The primary key of this table is rollNum.
The SQL query below is executed on this database.
The number of rows returned by the query is ______
The SQL query below is executed on this database.
SELECT *
FROM Student
WHERE gender = 'F' AND
marks > 65;
The number of rows returned by the query is ______
Answer: 2
Check the rows where gender = 'F' and marks 65:
- Aliya, 70: True
- Aliya, 80: True
- Swati, 65: False (65 is not more than 65)
SELECT * gives the whole row, so the repeated name is not a problem.
Answer: 2
- Aliya, 70: True
- Aliya, 80: True
- Swati, 65: False (65 is not more than 65)
SELECT * gives the whole row, so the repeated name is not a problem.
Answer: 2
Consider the relational database with the following four schemas and their respective instances.
The number of rows returned by the above SQL query is ___
Student(sNo, sName, dNo) Dept(dNo, dName)
Course(cNo, cName, dNo) Register(sNo, cNo)
|
|
|
|
SQL Query:
SELECT * FROM Student AS S WHERE NOT EXIST
(SELECT cNo FROM Course WHERE dNo = “D01”
EXCEPT
SELECT cNo FROM Register WHERE sNo = S.sNo)The number of rows returned by the above SQL query is ___
Answer: 2
The paper prints
The query picks the students for whom the set (D01 courses) EXCEPT (courses the student registered for) is empty. So it returns the students who registered for all D01 courses.
D01 courses = {C11, C12}.
- S01: registered C11, C12. True
- S02: registered C11 only. False
- S03: registered C21, C22, C23. False
- S04: registered C11, C12. True
- S05: registered C11, C21. False
Answer: 2
NOT EXIST; it stands for SQL's NOT EXISTS. Its Register row "S03 C 23" is course C23.The query picks the students for whom the set (D01 courses) EXCEPT (courses the student registered for) is empty. So it returns the students who registered for all D01 courses.
D01 courses = {C11, C12}.
- S01: registered C11, C12. True
- S02: registered C11 only. False
- S03: registered C21, C22, C23. False
- S04: registered C11, C12. True
- S05: registered C11, C21. False
Answer: 2
The relation scheme given below is used to store information about the employees of a company, where empId is the key and deptId indicates the department to which the employee is assigned. Each employee is assigned to exactly one department.
Consider the following SQL query:
Consider the following SQL query:
select deptId, count(*)
from emp
where gender = "female" and salary > (select avg(salary)from emp)
group by deptId;The above query gives, for each department in the company, the number of female employees whose salary is greater than the average salary ofAnswer: (B)
The inner query (select avg(salary) from emp) has no where condition. It is also not correlated with the outer query. So it gives the average salary of all employees in the company.
Answer: employees in the company
Answer: employees in the company
Keep practising