Unknown column 'people.contract_type' in 'order clause'
I've prefixed the 'archived' column with 'people.' but it doesn't complain about that. I did a test where I replaced people.archived != '9' with people.contract_type = '1' - it worked fine. As soon as I introduced a second condition in WHERE, it failed.
FROM (SELECT people.* ,
sin((IF(people.postcode != '',latitude,c_latitude)*pi()/180))+cos(('51.517626393425'*pi()/180)) *
cos((IF(people.postcode != '',latitude,c_latitude)*pi()/180)) *
cos((('-0.073421625736112' - IF(people.postcode != '',longitude,c_longitude))*pi()/180))))*180/pi())*60*1.1515)
LEFT JOIN ordnance_survey_locations ON people.postcode = ordnance_survey_locations.postcode
LEFT JOIN counties ON people.county = counties.id
WHERE people.archived != '9' AND people.contract_type = '2') dt
WHERE distance <= 20
ORDER BY distance ASC, people.contract_type ASC, name ASC, surname ASC
LIMIT 0, 50
Any help would be appreciated.