SELECT A.id, A.title,
FROM (`table`) as A
WHERE A.active = '1'
AND A.id IN (SELECT GROUP_CONCAT(B.id) from B where user = 3)
If i launch subquery SELECT GROUP_CONCAT(B.id) from B where user = 3 only, i obtain 1,2,3,4. But if i launch entire query i obtain only one row.
But if i try to substitute the subquery with its value (1,2,3,4)
SELECT A.id, A.title,
FROM (`table`) as A
WHERE A.active = '1'
AND A.id IN (1,2,3,4)
i obtain the 4 rows … as i need.
Where is my error ?
MySQL is seeing the subquery return only a single field/row, and therefore treats it as something like:
which boils down to
A.id = '1,2,3,4'.For an ‘in’ query, there’s no need for the group_concat stuff, simply do: