I actually have these tables :
- Table games -
ID
Name
- Table ean -
ID
ID_games
EAN
And I have this request :
SELECT games.*, ean.EAN
FROM games
LEFT JOIN ean ON (games.ID = ean.ID_games)
The result will be something like this :
| 1 | Half Life | 358958595 |
| 1 | Half Life | 589584859 |
| 2 | Half Life 2 | 385953684 |
| 2 | Half Life 2 | 585100335 |
etc.
When I do my request and use it in php, it is not useful to have a lot of line with about the same results. I would like to do something like this :
SELECT games.*, ConvertToArray(ean) AS ean_array
FROM games
LEFT JOIN ean ON (games.ID = ean.ID_games)
And have results like this :
| 1 | Half Life | (358958595,589584859) |
| 2 | Half Life 2 | (385953684,585100335 ) |
etc.
Is it possible to that with mysql ? Without an UDF ? And with an UDF ?
Thank you,
Kevin
Do you object to using
GROUP_CONCAT? This would give you a nice delimited list (Assuming theeanvalue will never have your delimiter within):Resulting in:
Also, here’s a qeustion I found with this logic applied: mySql – creating a join using a list of comma separated values