Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with SQL with LEFT JOIN for a radius search
    primarykey
    data
    text
    <p>I'm having some problems with my radius search. I have a table with zip codes, place names and geographical coordinates (based on OpenGeoDB).</p> <p>Here is my SQL-Command:</p> <pre><code>SELECT main.zc_zip, (ACOS( SIN(RADIANS(main.zc_lat)) * SIN(RADIANS(geo.zc_lat)) + COS(RADIANS(main.zc_lat)) * COS(RADIANS(geo.zc_lat)) * COS(RADIANS(main.zc_lon) - RADIANS(geo.zc_lon)) ) * 6380) AS `distance` FROM tx_sdfilmbase_geodb main LEFT JOIN tx_sdfilmbase_geodb geo ON geo.zc_location_name LIKE '%frauenfeld%' WHERE (ACOS( SIN(RADIANS(main.zc_lat)) * SIN(RADIANS(geo.zc_lat)) + COS(RADIANS(main.zc_lat)) * COS(RADIANS(geo.zc_lat)) * COS(RADIANS(main.zc_lon) - RADIANS(geo.zc_lon)) ) * 6380) &lt; 20 AND main.disabled=0 ORDER BY `distance` ASC </code></pre> <p>I get results for all locations around Frauenfeld within a radius of 20 kilometres. However, I don't get any result for locations named "frauenfeld" - i.e. I get all surrounding places but not the searched placed itself.</p> <p>How do I have to change the SQL to also get the place itself? I tried different things, but always the same result...</p> <p>Would be glad for some hints.</p> <p>Greets Stefan</p> <p><strong>Edit to answer comments by ypercube and Matt Gibson:</strong></p> <p>All entries in the database table have disabled=0 at the moment. </p> <p>Amongst many others, I get the following results (zip, distance):</p> <ul> <li>8552 3.7661608052471</li> <li>8500 4.184731709915</li> <li>8523 4.9298917004071</li> <li>9548 4.9771821340396</li> </ul> <p>Zip codes for Frauenfeld: 8500, 8501, 8502 and 8503.</p> <p>Missing entries in the result would be (zip, distance):</p> <ul> <li>8500 0</li> <li>8501 0</li> <li>8502 0</li> <li>8503 0</li> </ul> <p>However, the data in the geo database is correct (zip, place, latitude, longitude):</p> <ul> <li>8503 Frauenfeld 47.557707 8.897367</li> <li>8502 Frauenfeld 47.557707 8.897367</li> <li>8501 Frauenfeld 47.557707 8.897367</li> <li>8500 Frauenfeld 47.557707 8.897367</li> </ul> <p><strong>Edit to reply to answer by kuru kuru pa:</strong></p> <p>Thanks for your reply!<br> The Answer looks like this now (zc_location_name, zc_zip, disabled, distance): </p> <pre><code>Frauenfeld 8500 0 NULL Frauenfeld 8503 0 NULL Frauenfeld 8502 0 NULL Frauenfeld 8501 0 NULL Gerlikon 8500 0 4.18473170991499 </code></pre> <p>Why is it NULL and not 0? Any guesses? :-) Btw: Each result was listed 4 times (I just posted each once).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload