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