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 21–25 of 43

Q21GATE 20121 markMCQ−0.33 if wrong
Which of the following statements are TRUE about an SQL query?
P : An SQL query can contain a HAVING clause even if it does not have a GROUP BY clause
Q : An SQL query can contain a HAVING clause only if it has a GROUP BY clause
R : All attributes used in the GROUP BY clause must appear in the SELECT clause
S : Not all attributes used in the GROUP BY clause need to appear in the SELECT clause

Q22GATE 20112 marksMCQ−0.67 if wrong
Database table by name Loan_Records is given below.
BorrowerBank_ManagerLoan_Amount RameshSunderajan10000.00 SureshRamgopal5000.00 MaheshSunderajan7000.00
What is the output of the following SQL query?
 
SELECT count(*)
FROM(
(SELECT Borrower, Bank_Manager FROM Loan_Records) AS S
NATURAL JOIN
(SELECT Bank_Manager, Loan_Amount FROM Loan_Records) AS T); 

Q23GATE 20112 marksMCQ−0.67 if wrong
Consider a database table T containing two columns X and Y each of type integer. After the creation of the table, one record (X=1,Y=1) is inserted in the table.

Let MX and MY denote the respective maximum values of X and Y among all records in the table at any point in time. Using MX and MY, new records are inserted in the table 128 times with X and Y values being MX+1, 2*MY+1 respectively. It may be noted that each time after the insertion, values of MX and MY change.

What will be the output of the following SQL query after the steps mentioned above are carried out?

SELECT Y FROM T WHERE X=7;

Q24GATE 20101 markMCQ−0.33 if wrong
A relational schema for a train reservation database is given below
Passenger (pid, pname, age) Reservation (pid, class, tid) Table : Passenger Table : Reservation pidpnameAge 0'Sachin'65 1'Rahul'66 2'Sourav'67 3'Anil'69 pidclasstid 0'AC'8200 1'AC'8201 2'SC'8201 5'AC'8203 1'SC'8204 3'AC'8202
What pids are returned by the following SQL query for the above instance of the tables?
 SELECT pid
FROM Reservation
WHERE class = 'AC' AND
     EXISTS (SELECT *
                      FROM Passenger
                      WHERE age > 65 AND
                      Passenger.pid = Reservation.pid) 

Q25GATE 20082 marksMCQ−0.67 if wrong
Consider the following relational schema:
Student(school-id,sch-roll-no,sname,saddress)
School(school-id,sch-name,sch-address,sch-phone)
Enrolment(school-id,sch-roll-no,erollno,examname)
ExamResult(erollno,examname,marks) 

What does the following SQL query output?
SELECT	sch-name, COUNT (*)
FROM	School C, Enrolment E, ExamResult R
WHERE	E.school-id = C.school-id
AND
E.examname = R.examname AND E.erollno = R.erollno
AND
R.marks = 100 AND S.school-id IN (SELECT school-id
                                FROM student
                                GROUP BY school-id
                                 HAVING COUNT (*) > 200)
GROUP By school-id

Keep practising

Topics in Databases

All CS topics ›