This is incorrect.
Since distance is not a column, a where clause cannot be applied to it.
As you see below..
Code:
mysql> SELECT id, ( 3959 * acos( cos( radians(41) ) * cos( radians( lat ) ) * co
s( radians( lng ) - radians(-70) ) + sin( radians(41) ) * sin( radians( lat ) )
) ) AS distance FROM venueent HAVING distance < 250 ORDER BY distance;
+----+-----------------+
| id | distance |
+----+-----------------+
| 2 | 208.96648178691 |
| 4 | 209.35520222501 |
| 1 | 209.3636726854 |
| 5 | 209.86840227878 |
| 3 | 209.89832530515 |
| 6 | 210.09721899478 |
+----+-----------------+
6 rows in set (0.00 sec)
while using 'Where'
Code:
mysql> SELECT id, ( 3959 * acos( cos( radians(41) ) * cos( radians( lat ) ) * co
s( radians( lng ) - radians(-70) ) + sin( radians(41) ) * sin( radians( lat ) )
) ) AS distance FROM venueent WHERE distance < 250 ORDER BY distance;
ERROR 1054 (42S22): Unknown column 'distance' in 'where clause'
Also note these results from the debug console...
13:20:20,156 WARN JDBCExceptionReporter:77 - SQL Error: 1054, SQLState: 42S22
13:20:20,156 ERROR JDBCExceptionReporter:78 - Unknown column 'distance' in 'where clause'