已经有许多左连接问题,但我仍然不能完全解决这个问题。WHERE 条件看起来不适合移动。
问题是应该返回 4 行,但只有 1 行。
在检查左连接条件时,每个左连接返回 1 行,这对于表中的记录数是正确的,但是下面的查询返回 1 记录而不是 4,但我看不到如何返回 4 , 然而。
查询如下:(给出 1 个结果而不是 4 个;预期为 4 个)
SELECT
list.uid,
list.business_uid,
list.creator_name,
business.company_name,
list_alias.uid AS list_alias_uid,
list_alias.alias AS list_alias,
list_member.uid AS list_member_uid,
mailbox.full_name AS list_member_name,
mailbox.email_address AS list_member_email_address
FROM
mailbox,
business,
list
LEFT JOIN
list_alias ON list_alias.list_uid=list.uid
LEFT JOIN
list_member ON list_member.list_uid=list.uid
WHERE
list.business_uid='1'
AND list.business_uid=business.uid
AND mailbox.uid=list_member.mailbox_uid
ORDER BY
list.full_name ASC
数据:
业务 UID 1 有 4 个列表
SELECT * FROM list WHERE business_uid=1
-- 给出 4 个结果
SELECT * FROM list_alias WHERE list_uid IN (SELECT uid FROM list WHERE business_uid=1)
-- 给出 1 个结果
SELECT * FROM list_member WHERE list_uid IN (SELECT uid FROM list WHERE business_uid=1)
-- 给出 1 个结果
欢迎任何关于我可以检查的内容的指示。
表样本数据:
列表:
uid | business_uid | creator_name | full_name
--------------------------------------------------
1 1 List Maker Subscribe to W
2 1 List Maker Subscribe to X
3 1 List Maker Subscribe to Y
4 1 List Maker Subscribe to Z
商业:
uid | company_name
-------------------
1 List Company
列表别名:
uid | list_uid | alias
----------------------------------------
1 1 subscriber@list-url.com
列表成员:
uid | list_uid | mailbox_uid
------------------------------------
1 1 1
邮箱:
uid | full_name | email_address
-------------------------------
1 I am He me@me.com