Jump to content

query to list records from four tables


bickyz
Go to solution Solved by Barand,

Recommended Posts

hi i am trying to create a seach in php that will query follwing four mysql tables.

alltables01.jpg

 

I have following sql statement:

SELECT * FROM activities
JOIN incl_activity on activities.acid = incl_activity.acid
JOIN inclusion on incl_activity.incid = inclusion.incid
JOIN teamleader on activities.tlid2 = teamleader.tlid
WHERE activities.acdate = "2013-10-13"
ORDER BY teamleader.tlname ASC

which gives following result:

21mar131049.jpg

 

In above Jane Doe has three records, these three records are from same activity (Mountain Biking) on same Day and Duration whereas this activity includes Fishing, Gliding & Flying which are three difference records.. So is there anyway I can just list one record for one person. Or is this something I have to do in PHP script.

 

Any help would be much appreciated, thank you.

 

 

Link to comment
Share on other sites

  • Solution

try

 

SELECT activities.*, teamleader.tlname, GROUP_CONCAT(incdesc SEPARATOR ', ') as Includes  
FROM activities
JOIN incl_activity on activities.acid = incl_activity.acid
JOIN inclusion on incl_activity.incid = inclusion.incid
JOIN teamleader on activities.tlid2 = teamleader.tlid
WHERE activities.acdate = "2013-10-13"
GROUP BY activities.acid
ORDER BY teamleader.tlname ASC
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.