set @lat=39.1378100;set @lon = -77.6051500;set @dist = .7;set @rlon1 = @lon-@dist/abs(cos(radians(@lat))*69);set @rlon2 = @lon+@dist/abs(cos(radians(@lat))*69);set @rlat1 = @lat-(@dist/69);set @rlat2 = @lat+(@dist/69);select st_distance(point(@lon, @lat), thePoint) as distance, ListingID, ListingStatus, LotAreaAcre, LivingArea, ForSale, Longitude, ModificationTimestamp, YearBuilt, Latitude, Subdivision, VirtualTourURL, ListOfficeName, ListingKey, ZipCode, ListPictureURL,ListPicture3URL, FullStreetAddress, StreetName, Beds, BathsFull,BathsHalf, CityName, State, ZipCode, ListPrice, ClosePrice, InternetRemarks, LotAreaAcre from `searchALL` where st_within(thePoint, envelope(linestring(point(@rlon1, @rlat1), point(@rlon2, @rlat2)))) and (ListingStatus LIKE "Active%" or ListingStatus ='COMING SOON') and ForSale='Y' order by distance ASC, st_distance(point(@lon, @lat), thePoint) limit 50;