Hello,
I have 2 tables, one with restaurants and one with US centroids, latitudes longitudes, zipcodes for varius central cities in the us.
I have a query that I got working, that uses these 2 tables, it selects all restaurant data from table Restaurants city/state/zip... where the restaurant zipcodes are within the dynamic radius specified of the zipcode(centroid) specified.
This works fine, It also returns the distance as well.
I would also like to select restaurants records regardless if the the distance between zipcodes only IF the Restaurant City matched the CIty I pass to the query. I tried adding an OR operator but my query hung.
Here is my query:
If I add to the where clause OR R.RESTCITY = '$CITY' it will hang.
Any suggestions?
THANKS SO MUCH!!!
I have 2 tables, one with restaurants and one with US centroids, latitudes longitudes, zipcodes for varius central cities in the us.
I have a query that I got working, that uses these 2 tables, it selects all restaurant data from table Restaurants city/state/zip... where the restaurant zipcodes are within the dynamic radius specified of the zipcode(centroid) specified.
This works fine, It also returns the distance as well.
I would also like to select restaurants records regardless if the the distance between zipcodes only IF the Restaurant City matched the CIty I pass to the query. I tried adding an OR operator but my query hung.
Here is my query:
Code:
SELECT R.RESTID,R.RESTNAME,R.RESTADDRESS1,R.RESTCITY,R.RESTSTATE,R.RESTPHONE1,R.RESTPHONE2,R.RESTPHONE3,R.RESTZIP1,R.GENRE,R.SERVICE,
TRUNCATE (acos( (sin( Z1.LATITUDE * 0.017453293 ) * sin( Z2.LATITUDE * 0.017453293 ) ) + (cos( Z1.LATITUDE * 0.017453293 ) * cos( Z2.LATITUDE * 0.017453293 ) * cos( (Z2.LONGITUDE * 0.017453293) - ( Z1.LONGITUDE * 0.017453293 ) ) )) *3956,1) AS DISTANCE
FROM RESTAURANTS R, DINEZIPCODES Z1,DINEZIPCODES Z2
WHERE Z1.ZIPCODE = '$centroid' AND acos( (sin( Z1.LATITUDE * 0.017453293 ) * sin( Z2.LATITUDE * 0.017453293 ) ) + (cos( Z1.LATITUDE * 0.017453293 ) * cos( Z2.LATITUDE * 0.017453293 ) * cos( (Z2.LONGITUDE * 0.017453293) - ( Z1.LONGITUDE * 0.017453293 ) ) )) *3956
BETWEEN 0 AND '$radius' AND R.RESTZIP1 = Z2.ZIPCODE ORDER BY DISTANCE ASC
Any suggestions?
THANKS SO MUCH!!!