biggieuk Posted May 27, 2008 Share Posted May 27, 2008 Hi, I have two tables like so: session +----------+----------+----------+----------+ | groupid | group | mentor | room | +----------+----------+----------+----------+ | 1 | Sports | bob | l657 | resource +----------+----------+----------+----------+ | resourceid| name | path | groupid | +----------+----------+----------+----------+ | 1 | ball | ../1.jpg | 1 | Resources are assigned to a certain group and so the groupid is added to the resource table. I need to display a repeating table but i am unsure about the sql code that will enable me to get the following: +----------+----------+----------+----------+ | group | mentor | room | path | +----------+----------+----------+----------+ i need the path column to only contain a value for the groups that have had a resource assigned to them. Help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/107421-solved-query-multiple-tables-for-repeating-table/ Share on other sites More sharing options...
Barand Posted May 27, 2008 Share Posted May 27, 2008 SELECT s.group, s.mentor, s.room, r.path FROM session s JOIN resource r ON s.groupid = r.groupid Link to comment https://forums.phpfreaks.com/topic/107421-solved-query-multiple-tables-for-repeating-table/#findComment-551050 Share on other sites More sharing options...
biggieuk Posted May 27, 2008 Author Share Posted May 27, 2008 thanks for this however i don't think i explained what i wanted very clearly. This returns the rows of data that have a resource applied to them only. I need all of the rows from session to be displayed and if a resource has been added to that session then the path is displayed, otherwise the path field is left blank. I have tried: SELECT s.group, s.mentor, s.room, r.path FROM sessions s JOIN resource r This returns the whole of the sessions table and the same path for all of the sessions which shouldn't be the case. Link to comment https://forums.phpfreaks.com/topic/107421-solved-query-multiple-tables-for-repeating-table/#findComment-551184 Share on other sites More sharing options...
Barand Posted May 27, 2008 Share Posted May 27, 2008 in which case SELECT s.group, s.mentor, s.room, r.path FROM session s LEFT JOIN resource r ON s.groupid = r.groupid Link to comment https://forums.phpfreaks.com/topic/107421-solved-query-multiple-tables-for-repeating-table/#findComment-551187 Share on other sites More sharing options...
biggieuk Posted May 27, 2008 Author Share Posted May 27, 2008 brilliant, thanks! Link to comment https://forums.phpfreaks.com/topic/107421-solved-query-multiple-tables-for-repeating-table/#findComment-551190 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.