0

I have this table.

wppl_friends_locator

The table have columns named

lat float(10,6)

long float(10,6)

These columns have lat and long saved of entries, now i am trying to get results within radius of 30 miles from a given lat,long.

Sql does not return any results for some reasons which i am unable to figure out, below is the sql

SELECT
    member_id,
    (3959 * ACOS(
        COS(RADIANS(-19.943379)) *
        COS(RADIANS('lat')) *
        COS(RADIANS('long') - RADIANS(-43.9521885)) +
        SIN(RADIANS(-19.943379)) *
        SIN(RADIANS('lat'))
    )) AS distance
FROM
    wppl_friends_locator
HAVING
    distance < 30
ORDER BY
    distance;

so even if i do an entry in this table with same lat long which I am providing in sql query, It still does not return any results.

I have been stuck on it for few days, any help would be appreciated.

Table structure Table structure

Shidersz
  • 16,846
  • 2
  • 23
  • 48
  • 3
    would you please provide some sample data; include some that you expect the query to return within the distance < 30 (private data is not needed) – Paul Maxwell Oct 27 '18 at 04:41
  • 6
    `'lat'` and `'long'` are strings, not column names. change them to just `lat` and `long`. – Nick Oct 27 '18 at 04:58
  • 2
    Or use backtics `\`lat\`` – Rick James Oct 27 '18 at 05:14
  • 3
    Possible duplicate of [When to use single quotes, double quotes, and back ticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-back-ticks-in-mysql) – Nigel Ren Oct 27 '18 at 06:35
  • Thank You Nick and Rick, Thank You everyone finally the query worked. this returned results. SELECT member_id, (3959 * ACOS( COS(RADIANS(-19.943379)) * COS(RADIANS(`lat`)) * COS(RADIANS(`long`) - RADIANS(-43.9521885)) + SIN(RADIANS(-19.943379)) * SIN(RADIANS(`lat`)) )) AS distance FROM wppl_friends_locator HAVING distance < 30 ORDER BY distance Thank You Guys for Help! – user1030864 Oct 27 '18 at 09:04

0 Answers0