mabus Posted September 11, 2008 Share Posted September 11, 2008 My situation involves querying two tables. One table contains records that match the other in a one to many relationship. Example Person - Id - Name FavoriteColor -Id - Name - PersonId. The example above shows what my situation is like. This basically means that each peroson can have 0 or more FavoriteColors. Now, in this case that I want to come up with a table that contains the list of person, regardless if they have or not have any favorite colors. Sample Output (desired ouput) PersonName ColorName John Blue John Red Doe James Green Bill How will I be able to come up with a result like that? What I want is to be able to display results, even if a particular person profile has a matching color or not. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/123754-need-help-on-getting-table-results/ Share on other sites More sharing options...
Maq Posted September 11, 2008 Share Posted September 11, 2008 You need to join the tables where the Id from the 'Person' table equals the PersonId from the 'FavoriteColor' table. Select Name from the Person and Favorite Color table WHERE p.Id = fc.PersonId (to match the correct person and FavColor) Then loop through and display results. Try it and let me know if you need help. Quote Link to comment https://forums.phpfreaks.com/topic/123754-need-help-on-getting-table-results/#findComment-639040 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.