bickyz Posted March 21, 2013 Share Posted March 21, 2013 hi i am trying to create a seach in php that will query follwing four mysql tables. 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: 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. Quote Link to comment https://forums.phpfreaks.com/topic/275971-query-to-list-records-from-four-tables/ Share on other sites More sharing options...
Solution Barand Posted March 21, 2013 Solution Share Posted March 21, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/275971-query-to-list-records-from-four-tables/#findComment-1420129 Share on other sites More sharing options...
bickyz Posted March 21, 2013 Author Share Posted March 21, 2013 thank you very much Barand, I have included this query on my other PHP Search post. Quote Link to comment https://forums.phpfreaks.com/topic/275971-query-to-list-records-from-four-tables/#findComment-1420135 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.