Unknown column 'legal' in 'where clause'