【问题标题】:Sql join in other and other table [closed]Sql加入其他表和另一个表[关闭]
【发布时间】:2015-10-23 13:29:36
【问题描述】:

我正在尝试使用 LEFT JOIN 从其他表中获取结果。 我想使用 Join 显示用户位置。

我的数据库如下所示:

用户表:

#ID   |  location_id | email | pass
------------------------------------
  1   |   1          | ...    | ....

定位表:

#ID   |  county_id   | city_id | user_id
------------------------------------------
  1   |   1          |  1      |    2

国家表:

#ID   |  name     |  
-------------------
  1   |  Usa
  2   |  Belgium
  3   |  Serbia

城市表:

 #ID   |  name     |  
-------------------
  1   |  Berlin
  2   |  London
  3   |  New Your

【问题讨论】:

  • 您的预期输出是什么?你有没有尝试过任何东西?
  • 我真的希望这是coutnries 中的错字,而不是真正的表名。否则你会惹恼开发者和那些在未来几年维护这个表的人。 Locataion 也一样

标签: mysql sql


【解决方案1】:

试试这个方法

select * from usertable as a
join locataion as b on a.location_id=b.id
left join Coutnries as c on b.County_id = c.id
left join cities as d on b.City_id= d.id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    • 1970-01-01
    相关资源
    最近更新 更多