I have 2 tables.
TABLE_1
category_id name parent_id
1 test 0
2 test1 1
3 test2 1
4 test3 1
5 test4 2
.
TABLE_2
pro_id category_id name
1 2 prod1
2 2 prod2
3 3 prod3
4 5 prod4
.
.
.
I need to do this
- get all
category_ids whereparent_id = given...(say ‘1’) - query in another table with
where in (all the ids returned from 1) )… should bewhere in ('2,3,4')in the example case
OUTPUT
all fields of pro_id (1,2,3 in this case) from TABLE 2..
tried this.. (hoping this will work 🙂 )
select * from TABLE_2
where category_id in (select category_id from TABLE_1 where parent_id = 1)
but no result.
I could have done all this in PHP script. But had a problem with pagination. So I want to make it work in one query.
So is it possible to do this? Get the result from a query and use it in other in a single query? If so then I would appreciate your help.
this is weird .. but the query i provided was working…. 🙂 🙂
anywasy thanks guys…