I’m using a GROUP_CONCAT() in mysql to retrieve data from a list of ID stored like this :
**Table : Visitor**
ID | name | id_visited_place
--------------------------
1 | tom | 222,235,455
**Table : Places**
ID | Country | City | Date
--------------------------------------
222 | France | Paris | 2010-08-11
235 | Belgium | Antwerp | 2009-04-24
455 | Germany | Berlin | 2009-03-17
The problem is that this query only returns one field :
SELECT visitor.*, GROUP_CONCAT(places.country) AS country FROM visitor
LEFT JOIN Places ON FIND_IN_SET(places.id, visitor.id_visited_place)
GROUP BY visitor.id
But for each ID in id_visited_place, I would like to return each fields associated to this ID, like : “I visited Paris in France on 2010-08-11“
Then just leave out the group by:
Your join is multiplying the rows to get a separate row for each place. The group by is then reducing it back to one row per visitor.
That said, your data structure should not be using sets for this purpose. The number of places visited might grow beyond the maximum set size. Also, the join is rather difficult to follow and can’t take advantage of indexes.