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 6–10 of 43

Q6GATE 20201 markMCQ−0.33 if wrong
Consider a relational database containing the following schemas.
Catalogue sno pno cost S1 P1 150 S1 P2 50 S1 P3 100 S2 P4 200 S2 P5 250 S3 P1 250 S3 P2 150 S3 P5 300 S3 P4 250 Suppliers sno sname location S1 M/s Royal furniture Delhi S2 M/s Balaji furniture Bangalore S3 M/s Premium furniture Chennai Parts pno pname part_spec P1 Table Wood P2 Chair Wood P3 Table Steel P4 Almirah Steel P5 Almirah Wood
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

Q7GATE 20192 marksNAT
A relational database contains two tables Student and Performance as shown below:
Student Roll_no. Student_name 1 Amit 2 Priya 3 Vinit 4 Rohan 5 Smita Performance Roll_no. Subject_code Marks 1 A 86 1 B 95 1 C 90 2 A 89 2 C 92 3 C 80
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 _________ .

Q8GATE 20181 markMCQ−0.33 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?

Q9GATE 2017 (Session 1)1 markNAT
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
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 _____.

Q10GATE 2017 (Session 2)2 marksNAT
Consider the following database table named top_scorer.
top_scorer Player Country Goals Klose Germany 16 Ronaldo Brazil 15 G Müller Germany 14 Fontaine France 13 Pelé Brazil 12 Klinsmann Germany 11 Kocsis Hungary 11 Batistuta Argentina 10 Cubillas Peru 10 Lato Poland 10 Lineker England 10 T Müller Germany 10 Rahn Germany 10
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 ___________.

Keep practising

Topics in Databases

All CS topics ›