Skip to content
Advertisement

SQL join 2 times same table

I have a flight table like

And airport table like

How can I get all airports that made a flight to or brought in a flight from Amsterdam?

If I have a query with the where clause WHERE flight.origin = 1 OR flight.destination = 1 I also get Amsterdam in my results, while there is no flight from Amsterdam to Amsterdam.

Advertisement

Answer

Use an IN clause:

Or

(You can of course replace = 1 with = (select id from airport where name = 'Amsterdam').)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement