选择具有不同条件的一行

时间:2018-04-03 11:55:36

标签: php sql

https://i.stack.imgur.com/X6Nis.png

嗨,我试图使用SQL查询从其他3个表中获取结果表,但我无法实现。我确信它可以到达结果表。请帮我实现结果

1 个答案:

答案 0 :(得分:0)

你必须进行3次连接,并且必须重命名表locations,因为它出现了两次:

SELECT routes.id, src.title, dest.title, groups.title FROM routes 
  INNER JOIN locations as src ON (src.id = routes.src)
  INNER JOIN locations as dest ON (dest.id = routes.dest)  
  INNER JOIN groups ON (groups.id = routes.groups)