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 16–20 of 43

Q16GATE 2014 (Session 1)2 marksMCQ−0.67 if wrong
Given the following schema:
employees(emp-id, first-name, last-name, hire-date, dept-id, salary)
departments(dept-id, dept-name, manager-id, location-id)
You want to display the last names and hire dates of all latest hires in their respective departments in the location ID 1700. You issue the following query:
 SQL>SELECT last-name, hire-date
FROM employees
WHERE (dept-id, hire-date) IN
(SELECT dept-id, MAx(hire-date)
FROM employees JOIN departments USING(dept-id)
WHERE location-id = 1700
GROUP BY dept-id); 
What is the outcome?

Q17GATE 2014 (Session 2)2 marksMCQ−0.67 if wrong
SQL allows duplicate tuples in relations, and correspondingly defines the multiplicity of tuples in the result of joins. Which one of the following queries always gives the same answer as the nested query shown below:
Select * from R where a in (select S. a from S)

Q18GATE 2014 (Session 3)2 marksMCQ−0.67 if wrong
Consider the following relational schema:
Employee (empId, empName, empDept )
Customer (custId,custName, salesRepId, rating)
SalesRepId is a foreign key referring to empId of the employee relation. Assume that each employee makes a sale to at least one customer. What does the following query return?
SELECT empName 
FROM employee E 
 WHERE NOT EXISTS (SELECT custId
FROM customer C
WHERE C. salesRepId = E. empId
AND C. rating < > 'GOOD')

Q19GATE 20132 marksMCQ−0.67 if wrong
Consider the following relational schema.
Students(rollno: integer, sname: string)
Courses(courseno: integer, cname: string)
Registration(rollno: integer, courseno: integer, percent: real)
Which of the following queries are equivalent to this query in English?
“Find the distinct names of all students who score more than 90% in the course numbered 107”
(I)
SELECT DISTINCT S.sname
FROM Students as S, Registration as R
WHERE R.rollno=S.rollno AND R.courseno=107 AND R.percent >90
(II) Πsname(σcourseno=107 ∧ percent>90(Registration⋈Students))\Pi_{\text{sname}}\left(\sigma_{\text{courseno}=107\,\wedge\,\text{percent}>90}\left(\text{Registration}\bowtie\text{Students}\right)\right)
(III) {T∣∃S∈Students,∃R∈Registration (S.rollno=R.rollno∧\{T\mid \exists S\in \text{Students}, \exists R\in \text{Registration}\ (S.\text{rollno}=R.\text{rollno}\wedge
R.courseno=107∧R.percent>90∧T.sname=S.sname)}R.\text{courseno}=107\wedge R.\text{percent}>90\wedge T.\text{sname}=S.\text{sname})\}
(IV) {<SN>∣∃SR∃RP(<SR,SN>∈Students∧<SR,107,RP>∈Registration∧RP>90)}\{\lt S_N\gt \mid \exists S_R\exists R_P\left(\lt S_R,S_N\gt\in \text{Students}\wedge \lt S_R,107,R_P\gt\in \text{Registration}\wedge R_P>90\right)\}

Q20GATE 20122 marksMCQ−0.67 if wrong
Consider the following relations A, B and C:
A Id Name Age 12 Arun 60 15 Shreya 24 99 Rohit 11 B Id Name Age 15 Shreya 24 25 Hari 40 98 Rohit 20 99 Rohit 11 C Id Phone Area 10 2200 02 99 2100 01
How many tuples does the result of the following SQL query contain?
 SELECT A.Id
FROM A
WHERE A.Age > ALL (SELECT B.Age
FROM B
WHERE B.Name = 'Arun') 

Keep practising

Topics in Databases

All CS topics ›