mysql - 请帮我为此编写 sql 查询

标签 mysql join inner-join outer-join

表 1:-

name | location | Area | Region | Country
-----------------------------------------
abc    8          6      9        12

表 2:-

lid | lname | aid | rid | cid
def    8       6     9    12

表 3:-

aid | aname | rid | cid
6      ghi     9     12

表 4:-

rid | rname | cid
9      jkl     12

表 5:-

cid | cname
12     mno

如何在 mysql 中加入这 5 个表并检索“abc, def, ghi, jkl, mno ”;

最佳答案

我希望这对您有用。

SELECT table1.name, table2.lname ,table3.aname,table4.rname,table5.cname 
FROM table1 
WHERE 
LEFT JOIN table2 ON table2.lid = table1.location
LEFT JOIN table3 ON table3.aid = table1.area
LEFT JOIN table4 ON table4.rid = table1.region
LEFT JOIN table5 ON table5.cid = table1.country

关于mysql - 请帮我为此编写 sql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17248064/

相关文章:

mysql内连接查询运行缓慢

带有 IN 子句的 MySQL 内部连接

mysql - MySQL 中的条件内连接语句

php - 具有 3 个不同用户表的私有(private)消息系统

php - csv文件上传并更新mysql数据库

mysql - 如何执行简单的连接

mysql 联合不工作

mysql - Mysql如何选择某个用户未加入的组?

mysql - Spring + hibernate + postgresql 的设置

scala - 在 spark 中加入两个数据帧以仅返回一个匹配项