I have a relation that has airline routes and the airports that these flights go over on such routes. I'm trying to identify what routes skip over the same airports.
I have whittled down the relation into a table that should be possible to manipulate to create my desired result:
SELECT route_id, airport_id
FROM routes_airports
WHERE stops = false
ORDER BY route_id, airport_id;
I would like to match routes to one another when they have the same values for airport_id across their entries in the table while including the routes that exhibit this property.
So, for example, routes 5 and 7 both skip over airports 10,15,20, so they should be matched together, but not with say, route 10 which only skips over airports 10 and 20.
route_id | skipped_airport_id
----------+------------
1 | 76
2 | 21*
2 | 22*
4 | 42
5 | 21*
5 | 22*
7 | 15
7 | 16
7 | 17
7 | 18
7 | 46
9 | 26
11 | 19
14 | 45*
14 | 46*
14 | 47*
15 | 45*
15 | 46*
15 | 47*
17 | 78
20 | 20
I would like the above example data to result in a table with just the routes that have a match such as below.
route_id
----------
2
5
14
15