i have some problems with a Query seem IN dosen’t work with Group_concat, that is what i wrote
SELECT category, (
SELECT GROUP_CONCAT( DISTINCT `short` SEPARATOR ', ' )
FROM `ods_category`
WHERE cid IN (n.category)
ORDER BY cid
) AS catstring
FROM ods_news AS n
the problem is just the column “catstring” containe only 1st item found in subquery but if i replace
WHERE cid IN (n.category)
with
WHERE cid IN (19,18,3)
it’s work well but as u can see that isn’t dynamic
do u know why n.category limit to just one item?
idk if u need that but a sintetic strucure of tables is
ods_news ods_category
id | category cid | short
1 | 1 1 | AA
2 | 3 2 | BB
3 | 4,5 3 | CC
4 | 1,2,4 4 | DD
5 | 6 5 | EE
6 | 2,1,6 6 | FF
that is the results i have and what i want
results i get result i want
category | catstring category | catstring
1 | AA 1 | AA
3 | CC 3 | CC
4,5 | DD 4,5 | DD,EE
1,2,4 | AA 1,2,4 | AA,BB,DD
6 | FF 6 | FF
2,1,6 | BB 2,1,6 | BB,AA,FF
I created your test data and replaced the IN() with another function. It gives exactly the results you want:
Result is: