Hi all,

The query must not include people whose postcode is not within the given distance.

Code MySQL:
SELECT people.* , (((acos(sin((51.51777*pi()/180)) * sin((latitude*pi()/180))+cos((51.51777*pi()/180)) * cos((latitude*pi()/180)) * cos(((-0.079501- longitude)*pi()/180))))*180/pi())*60*1.1515) AS distance FROM people WHERE people.archived = '0' AND distance <= '5' ORDER BY distance DESC, people.name ASC, people.surname ASC LIMIT 0, 50

I'm getting the following error:
Unknown column 'distance' in 'where clause'

However, if I remove distance <= '5' from the WHERE clause, it works and furthermore, in my php looping through the rows, 'distance' is clearly being defined as I'm able to print the distance.

Thanks in advance,