-
A relational schema for a train reservation database is given below.
Passenger (pid, pname, age)
Reservation (pid, class, tid)
Table: Passenger
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)
-
- 0, 1
- 1, 2
- 1, 3
- 1, 5
- 0, 1
Correct Option: C
The solution is best understood in steps
1. select the process Id from reservation whose class is AC the condition is satisfied by 0, 1, 5, 3
2. select a passenger whose age > 65 and the pId of passenger id = pId of reservation id passenger whose ages > 65 are those of pId 1, 2, 3
and the pId common to reservation is 1 and 3.
The solution is best understood in steps
1. select the process Id from reservation whose class is AC the condition is satisfied by 0, 1, 5, 3
2. select a passenger whose age > 65 and the pId of passenger id = pId of reservation id passenger whose ages > 65 are those of pId 1, 2, 3
and the pId common to reservation is 1 and 3.
The solution is best understood in steps
1. select the process Id from reservation whose class is AC the condition is satisfied by 0, 1, 5, 3
2. select a passenger whose age > 65 and the pId of passenger id = pId of reservation id passenger whose ages > 65 are those of pId 1, 2, 3
and the pId common to reservation is 1 and 3.