A relational schema for a train reservation database is given below Passenger…

2010

A relational schema for a train reservation database is given below

Passenger (pid, pname, age)

Re servation (pid, cass, tid)

What pids are returned by the following SQL query for the above instance of the tables?

SLECT 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

Attempted by 125 students.

Show answer & explanation

Correct answer: C

Answer: pid 1 and pid 3.

Reason:

  • Find passengers with age > 65: pids 1 (66), 2 (67), and 3 (69).

  • Find Reservation rows with class 'AC': pids 0, 1, 5, and 3.

  • Take the intersection (both conditions must hold): pids 1 and 3.

  • Notes: pid 0 is age 65 (not >65), pid 2 has only 'SC' reservations (not 'AC'), and pid 5 has an 'AC' reservation but no Passenger row to satisfy the EXISTS subquery.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir