基本的SQL子查询可以获得两个以上的表

时间:2012-09-28 09:25:16

标签: sqlite

您好我有三张名为airportsflightscheckin的表格。从这张表中我需要检索一些字段,如:

flight.code,
flight.start_time,
flight.end_time,
flights.start_id,
flights.endid,
airports.name as sloc,
airports.name as eloc

条件是:

ckeckin.flight_id = flights.id,
airport.id = flights.startid, --for sloc
airports.id = flights.endid --for eloc

1 个答案:

答案 0 :(得分:1)

这样的东西?

select flights.code, flights.start_time, flights.end_time, 
flights.start_id, flights.endid, 
a.name as sloc, b.name as eloc
from flights
left join airports a on (flights.start_id = a.id)
left join airports b on (flights.endid = b.id)