Jump to content

query to list records from four tables


bickyz

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
https://forums.phpfreaks.com/topic/275971-query-to-list-records-from-four-tables/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.