mysql left outer join

前端 未结 1 1922
长情又很酷
长情又很酷 2020-12-31 14:03

I have two tables:

  1. employee with fields employee_id, firstname, middlename, lastname
  2. timecard with fields employee_id,time-
1条回答
  •  别那么骄傲
    2020-12-31 14:13

    You are filtering tc_date_transaction which filters all null values in this field, even those generated by the outer-join and therefore defeats its purpose. Move the filter "tc_date_transaction = "17/06/2010"" into the join clause and it will work.

    SELECT * 
      FROM employee LEFT OUTER JOIN timecard 
           ON employee.employee_id = timecard.employee_id and tc_date_transaction = "17/06/2010";
    

    or write

    SELECT * 
      FROM employee LEFT OUTER JOIN timecard 
           ON employee.employee_id = timecard.employee_id 
      where (tc_date_transaction = "17/06/2010" or tc_date_transaction is null);
    

    0 讨论(0)
提交回复
热议问题