Brian W Posted December 7, 2008 Share Posted December 7, 2008 I'm trying to figure this join stuff and am a little lost. I have two tables; Stores: id | name | details | location Location: id | name | details Every store is in a location but not every location has a store. I want to get a list of all the stores with their location's name also so I can list em using PHP. This is what i have for my SQL so far <?php $sql = "SELECT * FROM `Stores` LEFT JOIN `Locations` ON `Stores`.`Location`=`Locations`.`ID` ORDER BY `Stores`.`Location`"; ?> From what I've seen of other people's code, I need to do something with some syntax along the lines of "AS"... but haven't really found something like this yet while hunting my favorite tutorial site. Any help, input, whatnot appreciated. thanks Quote Link to comment https://forums.phpfreaks.com/topic/135854-solved-help-joining-please/ Share on other sites More sharing options...
Brian W Posted December 7, 2008 Author Share Posted December 7, 2008 nvm i guess. figures it out once I figured out what I should look for. "Alias" is what I should have been searching for to begin with... After trial and error (E_ALL!!!) i got it working. $sql = "SELECT Stores.Name AS Name, Stores.Location AS LID, Stores.ID AS ID, Locations.Name AS Location FROM Stores LEFT JOIN Locations ON Stores.Location=Locations.ID ORDER BY Location"; Thanks anyways guys Quote Link to comment https://forums.phpfreaks.com/topic/135854-solved-help-joining-please/#findComment-708180 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.