mysql - want the result of all employee even though he has not done any activity on particular day -
i have 4 tables;
employee_detailscolumnsemp_code,emp_nameactual_all_detailscolumnsemp_code,date,activity_id,card_id, ,quantityactivitiescolumnsactivity_id(primary key) ,activitycardscolumns cardcard_id(primary key) ,card_type
activities:
activity_id activity 1 tape laying 2 embossing 3 courier packing 4 thermal cards
card_id card_type 1 barcoding 2 big ribbon 3 biman employee_details
emp_code emp_name 1 shraddha 2 mayuri 3 kishori actual_all_detalis table:
emp_code date activity_id card_id quantity 1 2015-12-19 1 2 266 2 2015-12-19 1 3 300 3 2015-12-19 3 2 400 now query return emp_code activity though has not done employee on particular day , should return activity related card type.
example, result should return quantity 0 if emp_code 2 has not done activity on particular day, e.g.
emp_code date activity card_type quantity 2 2015-12-19 embossing barcoding 0
try this:
select emp_code, date, activity_id, card_id, quantity employee_details left join (cards inner join actual_all_detalis on cards.card_id = actual_all_detalis.card_id) on actual_all_detalis.emp_code = employee_details.emp_code datediff(date, '2015-12-19') = 0
Comments
Post a Comment