I have two tables like this table 1 id | name | stuff| 117 |foo |info about foo table 2 id | fooid| comments| 1 |117 |awesome recipe! 5 |117 |great taste! 8 |96 | nice pic! I am pretty sure I need to do a left join but I am not sure how to do it by id I need to select everything (*) from table 1 based on id and also get everything in table 2 that has fooid the same as id from table 1. But also not fail if there is no match in table 2...ie I still need table 1's data returned regardless. Can anyone give me some insight as to how to do this? Thanks in advance!
Would personally do it as 2 queries, otherwise you would end up duping the name and stuff from table 1. after selected the stuff from table 1, it's then just a case of where fooid='$res[id]'
Single query: SELECT * FROM `table1` LEFT JOIN `table2` ON table1.id = table2.fooid GROUP BY table1.id Code (markup):