This query aims to select all employees (e.empid and e.ename) who did not take any holidays (left join with holiday table where empid is null).

'SELECT e.empid, e.ename FROM emp e LEFT JOIN holiday h ON e.empid=h.empid WHERE e.empid IS NULL;'

However, the logic of this query is incorrect. If an employee did take a holiday, their empid will not be null in the holiday table and therefore the left join will not return null. To get all employees who did not take a holiday, the query should be:

'SELECT e.empid, e.ename FROM emp e LEFT JOIN holiday h ON e.empid=h.empid WHERE h.empid IS NULL;'

SQL Query to Find Employees Without Holidays: A Comprehensive Guide

原文地址: https://www.cveoy.top/t/topic/ouKy 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录