gpt4 book ai didi

mysql - 如何解决 left join with where 子句不起作用

转载 作者:行者123 更新时间:2023-11-29 02:39:37 28 4
gpt4 key购买 nike

我有一个使用 LEFT JOINWHERE 子句的查询,但是当我运行查询时,不匹配的数据不会显示在数据库中。我该如何解决这个问题?

SELECT tbguru.id, tbabsenpeg.NIK, tbabsenpeg.tgl 
FROM `tbguru`
LEFT JOIN tbabsenpeg ON tbguru.id = tbabsenpeg.NIK AND tbguru.kodeapp = tbabsenpeg.kodeapp
WHERE tbguru.kodeapp='Mantri-Lab 1020'
AND (tbabsenpeg.tgl = '2019-03-09' OR tbabsenpeg.tgl IS NULL);

最佳答案

我认为您需要 on 子句中第二张表的条件:

SELECT g.id, a.NIK, a.tgl 
FROM tbguru g LEFT JOIN
tbabsenpeg a
ON g.id = a.NIK AND
g.kodeapp = a.kodeapp AND
a.tgl = '2019-03-09'
WHERE g.kodeapp = 'Mantri-Lab 1020' ;

关于mysql - 如何解决 left join with where 子句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55604071/

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