SQL questions — page 1 of 2

Q55

GATE CS 2025 CS-1Relational QueriesNAT2 marks
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.
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)
Question figure
Show answer without attempting

Answer: 26

Q54

GATE CS 2025 CS-2Relational QueriesMSQ2 marks
Consider the following relational schema:

Students (rollno: integer‾\underline{\text{rollno: integer}}, name: string, age: integer, cgpa: real)
Courses (courseno: integer‾\underline{\text{courseno: integer}}, cname: string, credits: integer)
Enrolled (rollno: integer‾\underline{\text{rollno: integer}}, courseno: integer‾\underline{\text{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?
More than one option can be correct.
Show answer without attempting

Answer: A, C, D

Q61

GATE CS 2023 CSRelational QueriesNAT2 marks
Consider the following table named Student in a relational database. The primary key of this table is rollNum.

Student
rollNumnamegendermarks
1NamanM62
2AliyaF70
3AliyaF80
4JamesM82
5SwatiF65
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 ____________.
Show answer without attempting

Answer: 2

Q56

GATE CS 2022 CSRelational QueriesNAT2 marks
Consider the relational database with the following four schemas and their respective instances.

Student(sNo‾\underline{\text{sNo}}, sName, dNo) Dept(dNo‾\underline{\text{dNo}}, dName)
Course(cNo‾\underline{\text{cNo}}, cName, dNo) Register(sNo‾\underline{\text{sNo}}, cNo‾\underline{\text{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
S03C23
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___________.
Show answer without attempting

Answer: 2

Q31

GATE CS 2021 CS-2Relational QueriesMCQ2 marks−2/3 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‾\underline{\text{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
Show answer without attempting

Answer: B

Q13

GATE CS 2020 CSRelational QueriesMCQ1 mark−1/3 if wrong
Consider a relational database containing the following schemas (the tables Catalogue, Suppliers and Parts are shown in the figure).

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
Question figure
Show answer without attempting

Answer: A

Q51

GATE CS 2019 CSRelational QueriesNAT2 marks
A relational database contains two tables Student and Performance as shown below:

Student
Roll_no.Student_name
1Amit
2Priya
3Vinit
4Rohan
5Smita
Performance
Roll_no.Subject_codeMarks
1A86
1B95
1C90
2A89
2C92
3C80
The primary key of the Student table is Roll_no. For the Performance table, the columns Roll_no. and Subject_code together form 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 __________.
Show answer without attempting

Answer: 5

Q12

GATE CS 2018 CSRelational QueriesMCQ1 mark−1/3 if wrong
Consider the following two tables and four queries in SQL.

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?
Show answer without attempting

Answer: D

Q41

GATE CS 2018 CSRelational QueriesMCQ2 marks−2/3 if wrong
Consider the relations r(A,B)r(A, B) and s(B,C)s(B, C), where s.Bs.B is a primary key and r.Br.B is a foreign key referencing s.Bs.B. Consider the query

Q:r⋈(σB<5(s))Q: r \bowtie (\sigma_{B<5}(s))

Let LOJ denote the natural left outer-join operation. Assume that rr and ss contain no null values.

Which one of the following queries is NOT equivalent to QQ?
Show answer without attempting

Answer: C

Q23

GATE CS 2017 CS-1Relational QueriesNAT1 mark
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.
EmpIdEmpNameDeptName
1XYAAA
2XYBAA
3XYCAA
4XYDAA
5XYEAB
6XYFAB
7XYGAB
8XYHAC
9XYIAC
10XYJAC
11XYKAD
12XYLAD
13XYMAE
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 ____________.
Show answer without attempting

Answer: 2.6

Q46

GATE CS 2017 CS-2Relational QueriesNAT2 marks
Consider the following database table named top_scorer.
playercountrygoals
KloseGermany16
RonaldoBrazil15
G MüllerGermany14
FontaineFrance13
PeléBrazil12
KlinsmannGermany11
KocsisHungary11
BatistutaArgentina10
CubillasPeru10
LatoPoland10
LinekerEngland10
T MüllerGermany10
RahnGermany10
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 ____________.
Show answer without attempting

Answer: 7.0

Q52

GATE CS 2016 CS-2Relational QueriesNAT2 marks
Consider the following database table named water_schemes :
scheme_nodistrict_namecapacity
1Ajmer20
1Bikaner10
2Bikaner10
3Bikaner20
1Churu10
2Churu20
1Dungargarh10
The number of tuples returned by the following SQL query is _________.
with total(name, capacity) as
    select district_name, sum(capacity)
    from water_schemes
    group by district_name
with total_avg(capacity) as
    select avg(capacity)
    from total
select name
    from total, total_avg
    where total.capacity ≥ total_avg.capacity
Show answer without attempting

Answer: 2.0

Q29

GATE CS 2015 CS-3Relational QueriesMCQ1 mark−1/3 if wrong
Consider the following relation

Cinema(theater, address, capacity)

Which of the following options will be needed at the end of the SQL query
SELECT P1.address
FROM Cinema P1
such that it always finds the addresses of theaters with maximum capacity?
Show answer without attempting

Answer: A

Q31

GATE CS 2015 CS-1Relational QueriesMCQ1 mark−1/3 if wrong
SELECT operation in SQL is equivalent to
Show answer without attempting

Answer: D

Q61

GATE CS 2015 CS-1Relational QueriesNAT2 marks
Consider the following relations:

Student
Roll_NoStudent_Name
1Raj
2Rohit
3Raj
Performance
Roll_NoCourseMarks
1Math80
1English70
2Math75
3English80
2Physics65
3Math80
Consider the following SQL query.
SELECT S.Student_Name, sum(P.Marks)
FROM Student S, Performance P
WHERE S.Roll_No = P.Roll_No
GROUP BY S.Student_Name
The number of rows that will be returned by the SQL query is ________.
Show answer without attempting

Answer: 2

Q40

GATE CS 2015 CS-2Relational QueriesMCQ2 marks−2/3 if wrong
Consider two relations R1(A,B)R_1(A,B) with the tuples (1,5), (3,7) and R2(A,C)R_2(A,C) = (1,7), (4,9). Assume that R(A,B,C) is the full natural outer join of R1R_1 and R2R_2. Consider the following tuples of the form (A,B,C): a = (1,5,null), b = (1,null,7), c = (3,null,9), d = (4,7,null), e = (1,5,7), f = (3,7,null), g = (4,null,9). Which one of the following statements is correct?
Show answer without attempting

Answer: C

Q54

GATE CS 2014 CS-2Relational QueriesMCQ2 marks−2/3 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)
Show answer without attempting

Answer: C

Q54

GATE CS 2014 CS-3Relational QueriesMCQ2 marks−2/3 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');
Show answer without attempting

Answer: D

Q54

GATE CS 2014 CS-1Relational QueriesMCQ2 marks−2/3 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?
Show answer without attempting

Answer: B

Q35

GATE CS 2013 CSRelational QueriesMCQ2 marks−2/3 if wrong
Consider the following relational schema.

Students(rollno: integer‾\underline{\text{rollno: integer}}, sname: string)
Courses(courseno: integer‾\underline{\text{courseno: integer}}, cname: string)
Registration(rollno: integer, courseno: integer‾\underline{\text{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}}(\sigma_{\text{courseno}=107 \wedge \text{percent}>90}(\text{Registration} \bowtie \text{Students}))
(III) {T∣∃S∈Students,∃R∈Registration(S.rollno=R.rollno∧R.courseno=107∧R.percent>90∧T.sname=S.sname)}\{T \mid \exists S \in \text{Students}, \exists R \in \text{Registration} (S.\text{rollno}=R.\text{rollno} \wedge 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)}\{\langle S_N \rangle \mid \exists S_R \exists R_P (\langle S_R, S_N \rangle \in \text{Students} \wedge \langle S_R, 107, R_P \rangle \in \text{Registration} \wedge R_P > 90)\}
Show answer without attempting

Answer: A

0/200 correct0 marks

Related topics in Relational Queries