troubleshooting Question

show child records separated by commas

Avatar of Crazy Horse
Crazy HorseFlag for South Africa asked on
12 Comments1 Solution236 ViewsLast Modified:
I apologize if the title of the question doesn't match the question but I didn't know how else to describe it. Here is an example of my database table which shows the item and an ID. The ID from the below table is actually from a defect table which has an ID and description. This is from a previous question I posted on EE where I was selecting reasons via checkboxes. For simplicity I have used "car" and "bike". In the real world these would be unique identifiers.

Item     Defect
  car          5
  car          3
  car          7
  bike        9
  bike        2
  bike        5

I want to present this data in a html table that would look like this:

Car      Scratch, Broken window, burst tyre
Bike    Broken light, Missing seat, Scratch

I tired using GROUP BY which helped to just show one of each thing instead of doing this:


but then it doesn't show all of the reasons, it only shows one.

My current SQL:

SELECT `product_no`, `commit_date`, `non_green_desc` FROM `non_green` AS ng INNER JOIN `non_green_reasons` AS ngr ON ng.`ng_id` = ngr.`ng_id` WHERE `complete_date` = ? GROUP BY `tank_no`
Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros