I have two MySQL tables like this:
TableA
[name] | [id]
---------------------
Shirts 1, 10, 16, 18
Pants 14, 11
Skirts 19, 13, 15
TableB
[id] | [s_id]
---------------------
ABC 1
AC 1
DE 10
DEC 19
ACD 16
BCD 18
BCO 18
Now I need to get id
s from TableB
that matches s_id
that is from id
of TableA
for any given name.
The query would look like this:
SELECT id
FROM TableB
WHERE s_id IN ( SELECT id
FROM TableA
WHERE name = 'Shirts' )
So the sub-query returns 1, 10, 16, 18
(csv). But I know this cannot be used like this in the sub-query.
Any ideas?