I have 3 tables: Table1, Table2, Table3
I want to make a query that use Table1’s result as Table2’s constrain, Table2’s result as Table3’s constrain
so my query now is something like:
SELECT tb3.id
FROM tb3
WHERE tb3.tag = (
SELECT tb2.num
FROM tb2
WHERE tb2.name = (
SELECT tb1.user
FROM tb1
WHERE check = '0'
)
)
for example,
tb1 has item ‘tb1.check’, ‘tb1.user’;
tb2 has item ‘tb2.num’, ‘tb2.name’;
tb3 has item ‘tb3.tag’, ‘tb3.id’;
first check tb1 for data where ‘tb1.check’= 0 , then get its ‘tb1.user’,
then check tb2 for data where ‘tb2.name’ = ‘tb1.user’ and get ‘tb2.num’,
and so, check tb3 for data where ‘tb3.tag’ = ‘tb2.num’ then get ‘tb3.id’
but all I get is empty, any help?
use
INNER JOINinstead of subquery as: