whilst you could probably get this to work if you split the stringcodeids, this is a horribly inefficient query which will bog down as soon as you get a decent number of rows in either table, since the primary join will require an ALL join (it has to look in every row to see if its ID is present)
You should restructure table things so that it has 1 row per association. Either add an increment as a primary key or make both columns dual primary key
For Table things...
=================
| thingid | stuffid |
=================
| 1 | 1 |
| 2 | 1 |
| 2 | 3 |
| 2 | 4 |
| 4 | 2 |
=================
and the sql
[sql]
SELECT things.*, GROUP_CONCAT(stuff.code ORDER BY code SEPARATOR ', ') AS thingcodes
FROM things
LEFT JOIN stuff USING (stuffid)
WHERE things.stuffid = 2
GROUP BY things.thingid
[/sql]
note your where clause makes the group_concat irrelevant, as you are only selecting 1 row from that column.
|