gpt4 book ai didi

MySQL JOIN 使用三张表

转载 作者:行者123 更新时间:2023-11-29 00:23:12 26 4
gpt4 key购买 nike

我需要进行查询,从三个表中获取值。所以,我正在使用这个:

SELECT 
menussite.MSS_D1sMenu, menussite.MSS_CdiVertical,
verticais.VER_D1sVertical,
GROUP_CONCAT(submenussite.SSS_D1sSubMenuSite)

FROM menussite
LEFT JOIN verticais ON verticais.VER_CdiVertical = menussite.MSS_CdiVertical
LEFT JOIN submenussite ON submenussite.SSS_CdiMenuSite = menussite.MSS_CdiMenuSite
ORDER BY menussite.MSS_CdiMenuSite ASC

问题是有些单元格是空的,查询只显示与查询完全匹配的行。我需要做什么才能查询不忽略其他结果?

更新

这是一个 SQL fiddle :http://sqlfiddle.com/#!2/11eabb/2

最佳答案

尝试或修改此查询

SELECT 
m.menu as a, m.vertical as b, v.vertical as c, s.submenu as d
from menu m, vertical v, submenu s where m.id=v.id and m.id=s.id
ORDER BY m.menu ASC

结果

http://sqlfiddle.com/#!2/11eabb/5/0

A     B  C  D            e  
item 1 1 vertical 1 submenu 1
item 2 0 vertical 2 submenu 1

关于MySQL JOIN 使用三张表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20291368/

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