Results 1 to 15 of 15
Jan 28, 2011, 06:02 #1
- Join Date
- Nov 2008
- 0 Post(s)
- 0 Thread(s)
MySQL variable can't be used in sort
The query must not include people whose postcode is not within the given distance.
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,