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