SQL: GATE CS Previous Year Questions

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

Q1GATE 2025 (Session 1)2 marksNAT
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.
player
pidpnameage
1Jasprit31
2Atharva24
3Ishan26
4Axar30
coach
cidcname
101Ricky
102Mark
103Trevor
team
tidtnamecitycid
10MIMumbai102
20DCDelhi101
30PKMohali103
members
pidtid
110
230
310
420
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)

Q2GATE 2025 (Session 2)2 marksMSQ
Consider the following relational schema:

Students(rollno: integer,‾ name: string, age: integer, cgpa: real)\text{Students} (\text{\underline{rollno: integer,} name: string, age: integer, cgpa: real})
Courses(courseno: integer,‾ cname: string, credits: integer)\text{Courses} (\text{\underline{courseno: integer,} cname: string, credits: integer})
Enrolled( rollno: integer,‾ courseno: integer,‾ grade: string)\text{Enrolled} (\text{ \underline{rollno: integer,} \underline{courseno: integer,} grade: string})

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.

Q3GATE 20232 marksNAT
Consider the following table named Student in a relational database. The primary key of this table is rollNum.
rollNumnamegendermarks1NamanM622AliyaF703AliyaF804JamesM825SwatiF65\begin{array}{|c|c|c|c|} \hline \\ rollNum&name&gender&marks \\ \hline 1&Naman&M&62\\ \hline 2&Aliya&F&70 \\ \hline 3&Aliya &F&80 \\ \hline 4&James&M&82\\ \hline 5&Swati&F&65\\ \hline \end{array}
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 ______

Q4GATE 20222 marksNAT
Consider the relational database with the following four schemas and their respective instances.

Student(sNo, sName, dNo)  Dept(dNo, dName)

Course(cNo, cName, dNo)  Register(sNo, cNo)
Student
sNosNamedNo
S01JamesD01
S02RockyD01
S03JacksonD02
S04JaneD01
S05MilliD02
Dept
dNodName
D01CSE
D02EEE
Course
cNocNamedNo
C11DSD01
C12OSD01
C21DED02
C22PTD02
C23CVD03
Register
sNocNo
S01C11
S01C12
S02C11
S03C21
S03C22
S03C 23
S04C11
S04C12
S05C11
S05C21

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 ___

Q5GATE 2021 (Session 2)2 marksMCQ−0.67 if wrong
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.

emp(empId‾, name, gender, salary, deptId)\textsf{emp($\underline{\textsf{empId}}$, name, gender, salary, deptId)}

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 of

Keep practising

Topics in Databases

All CS topics ›