The GATE Grind

GATE 2010 CS (CS1) – Question 29

Databases · Relational Model: Relational Algebra, Tuple Calculus, SQL · 1 mark · Multiple choice

Passenger(pid,pname,age) has (0,Sachin,65),(1,Rahul,66),(2,Sourav,67),(3,Anil,69). Reservation(pid,class,tid) has (0,AC,8200),(1,AC,8201),(2,SC,8201),(5,AC,8203),(1,SC,8204),(3,AC,8202). Which pids result?

SELECT pid FROM Reservation
WHERE class='AC' AND EXISTS
 (SELECT * FROM Passenger
  WHERE age>65 AND Passenger.pid=Reservation.pid);
  1. 1,0
  2. 1,2
  3. 1,3
  4. 1,5

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (C) 1,3

Explanation

AC reservations have pids zero,one,five,three. The correlated EXISTS requires a matching passenger older than sixty-five. Zero fails the strict age condition and five has no passenger row; one and three qualify. Thus C.

More Relational Model: Relational Algebra, Tuple Calculus, SQL questions

All Relational Model: Relational Algebra, Tuple Calculus, SQL questions →