How to count in LEFT JOIN table

Viewed 26

I need to get only NULL values in checktime or pin columns

enter image description here

My SQL query

SELECT emp.`emp_id`,cio.`pin`,cio.`checktime` FROM payroll.employees AS emp 

    LEFT JOIN (SELECT * FROM zkteco_biotime.checkinout WHERE checktime > "2022-09-20 23:59:59") AS cio ON emp.emp_id = cio.pin

    WHERE emp.status=0 GROUP BY emp_id ORDER BY checktime DESC

when i use AND cio.checktime=NULL after emp.status=0 it showing me result blank

1 Answers

You should use

AND cio.checktime IS NULL

Null compared with anything will result in FALSE. Only "IS NULL" and "IS NOT NULL" may return TRUE.

Related