Unknown column 'apply' in 'where clause'