select distinctrow table1.* from table1,table2 where table1.category=1 or (table1.category = table2.id and table2.parent_id = 1);