Mysql Left join with condition on column
- by skicster
Hi, can you help me with sql query?
I have this problem:
I have two tables
"Join" table: Reservation_has_meal
+----------------+
| id_reservation |
| id_meal |
| pieces |
+----------------+
and table with data: Meal
+-------------+
| id_meal |
| name |
+-------------+
Sample data for
Meal:
1 | carrot
2 | potatoe
3 | cucumber
Reservation_has_meal
1 | 2 | 5230
1 | 3 | 1203
How can I get this result for reservation with id_reservation=1:
id_meal | id_Reservation | name | pcs |
--------------------------------------------
1 | 1 | carrot | null|
2 | 1 | potatoe | 5230|
3 | 1 | cucumber | 1203|
--------------------------------------------
And result for id_reservation = 2:
id_meal | id_Reservation | name | pcs |
--------------------------------------------
1 | 2 | carrot | null|
2 | 2 | potatoe | null|
3 | 2 | cucumber | null|
--------------------------------------------
Thanks for advice.