I have a SQL Server database with three tables: Trips, Slices, and Legs.
Each Trip has a one to many relationship with Slices and Slices has a one to many relationship with Legs.
Trips represents a full trip, a slice represents only the outbound or return portions of a trip, and the legs represent all the stops in either outbound or return slices.
I want to be able to find all the trips with matching legs.
Here's look at the tables:
Trips:
tripId saleTotal queryDate
1 $200 6/10/2015
2 $198 6/11/2015
Slices:
sliceId connections duration tripIdFK
1 1 50 1
2 1 45 1
3 0 60 2
4 1 85 2
Legs:
legId carrier flightNumber departureAirport departureDate ArrivalAirport ArrivalDate sliceIDFK
1 AA 1 JFK 7/1/2015 LON 7/2/2015 1
2 AA 2 LON 7/2/2015 FRA 7/2/2015 1
3 AA 11 FRA 7/10/2015 LON 7/10/2015 2
4 AA 12 LON 7/10/2015 JFK 7/10/2015 2
5 UA 5 EWR 8/1/2015 LAX 8/1/2015 3
6 UA 6 LAX 8/5/2015 ORD 8/5/2015 4
7 UA 7 ORD 8/5/2015 EWR 8/5/2015 4
How would I be able to find all the trips where the all the carrier and flight numbers match such as in legId 1-4 by searching departureAirport/arrivalAirport (JFK/FRA)?
In other words, legId 1-4 is one unit with the details for Trip 1 and legId 5-7 is another unit with the details for Trip 2. I need to find which other trips match exactly legId 1-4 details (except for PK and FK), etc. Any help would be greatly appreciated!!