我有兩個表:Mysql的選擇 - 全部由左,只有匹配的右表
employees
[ID,名字,姓氏,狀態]
absence
[id,employee_id,reason_type,date_from,date_to
我可以這樣做:
SELECT e.first_name, e.last_name, e.status, a.reason_type FROM employees e JOIN absence a ON e.id=a.employee_id
WHERE curdate() between date_from and date_to
,但它會給我只在absence
表中找到這些員工。
有沒有辦法讓所有員工的名單和他們的狀態(對於那些在absence
表匹配條件currdate() between date_from and date_to
回「是」和reason_type
找到)和其他人說沒有和空值reason_type
。
感謝。
做一個'LEFT JOIN'。 – jarlh