Questions About Aco Records

How can I include a BETWEEN output and one record that's an exception in the same MySQL output?

I'm working in MySQL with PHP. I'm doing a query for a zip code from one table which contains the zip codes and the lat/lon for each zip code. The second table contains the zip code and average income for that zip code. The user gives a zip code (let's call this the base zip code) and it returns a 15 mile radius of zip codes. Via the web page the user can query with a range of incomes that uses a BETWEEN for MySQL in PHP.

My problem is, depending on what range the user selects, their base zip code might not appear all the time because it's outside of the income ranges. When this happens it is confusing to the user because the sorted output doesn't include their base zip code. I want to be able to include the base zip code as if there was no income range specified.

How can I include the ranged data (that uses the BETWEEN) and include the base zip code's data so it still takes advantage of MySQL's ORDERing of the output. Thanks!

UPDATE: Here is the working quer

http://www.stackoverflow.com/questions/12770662/how-can-i-include-a-between-output-and-one-record-that-s-an-exception-in-the-same-mysql-output

Optimising a haversine formula SQL call in PHP

I'm creating an MySQL call using PHP, I'm calculating distance using the haversine forumula:

SELECT name, id,
   (6371 * acos(cos(radians(' . $lat . ')) 
   * cos(radians(geoname.latitude)) 
   * cos(radians(geoname.longitude) - radians(' . $lon . ')) 
   + sin(radians(' . $lat . ')) 
   * sin(radians(geoname.latitude)))) AS distance 

My question is; is it best to do all this calculation in SQL? This query searches a table with around 1000 records. Would it be more efficient to do some of the math in PHP rather than SQL? Is there a better way to optimise this query?

http://stackoverflow.com/questions/2226489/optimising-a-haversine-formula-sql-call-in-php