Jump to content

[SOLVED] Query multiple tables for repeating table


biggieuk

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.