mysql - Join tables keeping empty results -
i have 2 tables need cross , return many results ids of 1 of them.
the first table of roles/tasks:
id | rolename ---+--------- 1 | check_in 2 | cleaning 3 | taxi 4 | guide 5 | car_rental 6 | meals 7 | house_owner 20 | custom and table has columns:
id | client_booking_id | staff_role_id | confirmed | staff_cost i need query gives me many results nr of columns in first table. because each unique client_booking_id there 1 (if any) of tasks/roles.
so if do:
select sr.role_name, sr.id, ss.staff_cost, ss.confirmed staff_role sr left join staff_schedule ss on sr.id=ss.staff_role_id i result nr of rows want. need match specific client_booking_id did
select sr.role_name, sr.id, ss.staff_cost, ss.confirmed staff_role sr left join staff_schedule ss on sr.id=ss.staff_role_id ss.client_booking_id=1551 // <-- new line and gives me 2 results because in second table have booked 2 tasks id.
but need result tasks not match, null values. how can this?
with query (without where clause) rows null , non-null values client_booking_id. want match specific client_booking_id , @ same time leave records null values, add additional condition specific client_booking_id left join.
moving condition left join:
select sr.role_name , sr.id , ss.staff_cost , ss.confirmed staff_role sr left join staff_schedule ss on sr.id = ss.staff_role_id , ss.client_booking_id = 1551
Comments
Post a Comment