Selecting Select count(*) as count FROM (Select * from foto_gallery where Active = 1 AND (n.category_id='29' OR n.category_id_2='29' OR n.category_id_3='29') order by `date` DESC ) as tb1 - Unknown column 'n.category_id' in 'where clause'