Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>select t1.post_id, t1.meta_value as lat, t2.meta_value as lon from metatdatatable t1, metadatatable t2 where t1.meta_key = "_wp_field1" and t2.post_id = t1.post_id and t2.meta_key = "_wp_field2" </code></pre> <h2>Edit</h2> <p>...to use this as the basis for yr lat/long calc, you can either create a temp table, or use the results inline with a query similar to the (simplified DISTANCE calc) below</p> <pre><code>select d1.post_id, d1.distance from (select r1.post_id, ABS($lat - r1.lat) + ABS($lon - r1.lon) as DISTANCE from (select t1.post_id, t1.meta_value as lat, t2.meta_value as lon from metatdatatable t1, metadatatable t2 where t1.meta_key = "_wp_field1" and t2.post_id = t1.post_id and t2.meta_key = "_wp_field2") as r1 ) as d1 where d1.distance &lt;= 10 order by d1.distance ASC </code></pre> <p>NB. you might want to apply a rough filter to your lat/long results before doing the 'expensive' lat/long calculation on the results, or before storing in a temp table. The idea would be to ignore all of the r1 results clearly outside of a 10 mile radius. </p> <p>If you use a temp table it will be user session specific.</p> <h2>Edit 2</h2> <p>Have a look at <a href="http://calgary.rasc.ca/latlong.htm" rel="noreferrer">Shape of the Earth</a> for details, but essentially 7 minutes lat &amp; longitude is always greater than 10 miles, so if your lat &amp; longs are recorded in degrees this is 0.117 near enough. Any point differing by more than 0.117 from your target cannot be inside your 10 mile radius. This means you can filter the r1 table like :</p> <pre><code>(select t1.post_id, t1.meta_value as lat, t2.meta_value as lon from metatdatatable t1, metadatatable t2 where t1.meta_key = "_wp_field1" and t2.post_id = t1.post_id and t2.meta_key = "_wp_field2" and ABS(t2.meta_value - $lon) &lt; 0.117 and ABS(t1.meta_value - $lat) &lt; 0.117 ) as r1 </code></pre> <p>NB. If your data spans the Greenwich Meridian, International Date Line or Equator, this will not be strictly correct. Assuming all of your lat/longs are for North America it won't be a problem.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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