Jessica Posted April 11, 2008 Share Posted April 11, 2008 Hey guys. I am trying to get info out of a database. There is a table of "foods" and a table of "brands". Some foods have a brandID, and some don't (0). I want to select all of the foods and their brand. The problem is when I do this: SELECT food.*, brands.* WHERE food.brandID = brand.brandID I don't get the food items that don't have a brand. The obvious solutions is to do 2 sql statements, selecting the foods and then the brands, then using PHP to put them together. But, is there a way to do it in one statement? Thanks! Link to comment https://forums.phpfreaks.com/topic/100676-solved-selecting-from-multiple-tables-trouble/ Share on other sites More sharing options...
rhodesa Posted April 11, 2008 Share Posted April 11, 2008 Try: SELECT * FROM food LEFT JOIN brands ON food.brandID = brands.brandID Link to comment https://forums.phpfreaks.com/topic/100676-solved-selecting-from-multiple-tables-trouble/#findComment-514877 Share on other sites More sharing options...
Jessica Posted April 11, 2008 Author Share Posted April 11, 2008 Awesome, the only thing I had to do was add the brands.* to get the actual brand info. SELECT food.*, brands.* FROM food LEFT JOIN brands ON food.brandID = brands.brandID Link to comment https://forums.phpfreaks.com/topic/100676-solved-selecting-from-multiple-tables-trouble/#findComment-515024 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.