如何解决带有where子句的左联接不起作用

时间:2019-04-10 02:54:45

标签: mysql sql

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

WHERE

2 个答案:

答案 0 :(得分:1)

我认为您想要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' ;

答案 1 :(得分:0)

您需要放置“ where”子句

  

tbguru.kodeapp ='Mantri-Lab 1020'

底部

SELECT tbguru.id, tbabsenpeg.NIK, tbabsenpeg.tgl 
FROM `tbguru` LEFT JOIN tbabsenpeg 
     ON tbguru.id = tbabsenpeg.NIK 
     AND tbguru.kodeapp = tbabsenpeg.kodeapp 
     AND tbabsenpeg.tgl = '2019-03-09' 

WHERE tbguru.kodeapp='Mantri-Lab 1020'