我有一个使用LEFT JOINwithWHERE子句的查询,但是当我运行查询时,数据库中不会显示不匹配的数据。我怎样才能解决这个问题?

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 - 如何解决带有where子句的左联接不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55604071/

10-11 03:09