gpt4 book ai didi

php - 同一列上两个表的 MySQL Left Join 返回 NULL 值

转载 作者:行者123 更新时间:2023-11-30 23:46:24 25 4
gpt4 key购买 nike

我有两个表 entity_finantial_trxn

enter image description here

finantial_trxn

enter image description here

当我在同一列上尝试两个左连接时,我得到其中一个的 NULL 值。

查询 -

SELECT *
FROM `financial_trxn` ft
LEFT JOIN entity_financial_trxn eft
ON eft.financial_trxn_id = ft.id AND eft.entity_table = 'contribution'
LEFT JOIN entity_financial_trxn eft1
ON eft1.financial_trxn_id = ft.id AND eft1.entity_table = 'financial_item'

为什么它为 entity_table 返回 NULL,即使我对它们的所有行都有值?

由于这个原因,我没有得到所需的输出,因为上述查询的附加 Where clase 隐藏了 NULL 行

WHERE (eft1.entity_table IS NOT NULL)

结果: enter image description here

最佳答案

您的查询是错误的,将您的查询更改为:

SELECT *
FROM `financial_trxn` ft
LEFT JOIN entity_financial_trxn eft
ON eft.financial_trxn_id = ft.id
where eft.entity_table = 'contribution' OR eft.entity_table = 'financial_item'

关于php - 同一列上两个表的 MySQL Left Join 返回 NULL 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34987070/

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