GATE CS 2010 · SQL Queries

MCQ · 1 mark · Problem DBMS-SQL-0111

A relational schema for a train reservation database is given below.Passenger (pid, pname, age)Reservation (pid, class, tid)\[\begin{array}{cc} \textbf{Passenger} & \textbf{Reservation} \\ \begin{array}{|c|l|c|} \hline \text{pid} & \text{pname} & \text{age} \\ \hline 0 & \text{Sachin} & 65 \\ 1 & \text{Rahul} & 66 \\ 2 & \text{Sourav} & 67 \\ 3 & \text{Anil} & 69 \\ \hline \end{array} & \begin{array}{|c|c|c|} \hline \text{pid} & \text{class} & \text{tid} \\ \hline 0 & \text{AC} & 8200 \\ 1 & \text{AC} & 8201 \\ 2 & \text{SC} & 8201 \\ 5 & \text{AC} & 8203 \\ 1 & \text{SC} & 8204 \\ 3 & \text{AC} & 8202 \\ \hline \end{array} \end{array}\]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)
  1. A
    1,0
  2. B
    1,2
  3. C
    1,3
  4. D
    1,5

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solution\[\boxed{\text{AC reservation whose passenger is older than } 65}\]AC reservations: pids \(0, 1, 5, 3\).pid \(0\) is exactly \(65\) (not \(> 65\)); pid \(5\) has no passenger row; pids \(1\) (66) and \(3\) (69) qualify.Answer: C

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com