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