gpt4 book ai didi

mysql - 3 个表中的左外连接

转载 作者:行者123 更新时间:2023-11-29 06:05:58 25 4
gpt4 key购买 nike

我有 3 张 table
车间和业主
shop是父表,另外2个是子表

SHOP    
s_id, floor_id,s_owner,s_remarks
1,2,1,big shop
2,2,3,near bank
3,1,2,corner
4,7,7,FAKE FLOOR AND OWNER

OWNERS
o_id, o_name, contact
1,gale,009659999999
2,smith,00447676767
3,pathan,0088787878

FLOORS
f_id, f_name
1,FIRST FLOOR
2,SECOND FLOOR
3,THIRD FLOOR


select shop.s_id, floors.f_name, owners.o_id, s_remarks
from ? join ?

即使业主或楼层没有相关记录,也可显示店铺的所有记录

最佳答案

正如您在标题中所建议的,您需要使用LEFT JOIN。这应该可以帮助您开始:

SELECT shop.s_id, floors.f_name, owners.o_id, s_remarks
FROM ?
LEFT JOIN ? ON ? = ?
LEFT JOIN ? ON ? = ?

您只需将问号替换为正确的表或列名称。

关于mysql - 3 个表中的左外连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11487383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com