# Relational algebra for multiple legs of a flight

I'm trying to write the relational algebra for a problem related to this schema:

I want to do the following: For each flight list the departure airport code for the first leg of the flight and the arrival airport code for the third leg.

I know how to do this for the individual parts, but I'm not sure how to select from multiple different instances of leg_instance.

This is what I have to start:

π airport.airport_code (flight) ⋈ flight.flight_number = leg_instance.flight_number (leg_instance) σ leg_instance.leg_number = 1

• A join operator will be necessary, at some point. – André Souza Lemos Nov 23 '16 at 20:18