I have 2 tables in mysql. I want to JOIN them but even if no matching data from 2nd table, I need to show NULL but join them.
table1
id | name
-----------
1 | name1
2 | name2
3 | name3
and second table
table2
id | service | amount
------------------------
1 | service1 | 10
2 | service2 | 20
3 | service1 | 20
4 | service3 | 10
and the output I need is,
output
name | amount
--------------
name1 | 10
name2 | NULL
name3 | 20
I have tried following query
SELECT t1.name,t2.amount
FROM table1 t1
LEFT JOIN table2 t2 ON t1.id = t2.id
WHERE t2.service=1
But it will not return name2 since there is no matching id in 2nd table. How can I do that?