I'm using the following to find the nearest 10 records by proximity
to the ZIP code $zip. The problem is that it only returns one record
per ZIP code, even when there are multiple records with the same ZIP:
(Note this uses a temp table, but I already double-checked that all
the desired records are making it into the temp table.)
SELECT $tmp.zip, $tmp.state, $tmp.name, $tmp.addr1, $tmp.addr2,
$tmp.addr3, $tmp.city, $tmp.state, $tmp.zip, $tmp.web, $tmp.email,
$tmp.phone,
ROUND((3956 * (2 * ASIN(SQRT(
POWER(SIN((($tmp.lat-zips.lat)*0.017453293)/2),2) +
COS($tmp.lat*0.017453293) *
COS(zips.lat*0.017453293) *
POWER(SIN((($tmp.lon-zips.lon)*0.017453293)/2),2))))),2) AS distance
FROM zips,$tmp
WHERE
$tmp.account_id='$account_id' AND zips.zip='$zip'
GROUP BY distance
order by distance
limit 10
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]