So I have the following normal query:
SELECT
someCol,
COUNT(*),
GROUP_CONCAT(myTableID SEPARATOR ',')
FROM myTable
GROUP BY someCol
I would like to use the list of myTableIDs in the third column in a subquery's IN clause. The following non-working query illustrates this:
# this does not work
SELECT
someCol,
COUNT(*),
( SELECT COUNT(mySubTable.*)
FROM mySubTable
WHERE mySubTable.foreignID IN GROUP_CONCAT(myTable.myTableID SEPERATOR ',')
) AS FOREIGN_COUNT
FROM myTable GROUP BY someCol
The IN GROUP_CONCAT()
part doesn't work because the GROUP_CONCAT() is just returning a string with commas, not an actual list of ids or a subquery.
My question is, is it possible to use the aggregate list of myTableIDs as part of the IN clause of the subquery?