Query 1 :- Select category_id from test where main_category='0'; Query 2 :- Select category_id from test where main_category=(result from query 1)