MySQL 查询问题?

A表

idname
1a
2b

B表

idname
1aa
2bb

C表

idname
1aaa
2bbb

D表

ida_idb_idc_id
1121
2002
3202
SELECT d.id, a.name AS a_name, b.name AS b_name, c.name AS c_name
FROM D AS d, A AS a, B AS b, C AS c
WHERE d.a_id = a.id AND d.b_id = b.id AND d.c_id = c.id

现在只要D表有0,就查询不出整条记录,怎么能查出全部,如果D表没有关联的那name就为空

阅读 1.2k
1 个回答

仅供参考

select d.id, a.name as a_name, b.name as b_name, c.name as c_name
from D as d
left join A as a on a.id=d.a_id
left join B as b on b.id=d.b_id
left join C as c on c.id=d.c_id
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题