Skip to main content
2 of 2
added 294 characters in body
user4951
  • 1.4k
  • 5
  • 20
  • 39

What is the SQL command to get 20 closest points from some center location

There are 1.6 million rows.

Must not compute distance for all rows.

Spatial index is available

This is the table structure. The name of the table is businessauxiliary. So yes I used MyIsam, added my spatial index. Then what? What's the SQL command?

If you can point me to a web it'll be great.

    BusinessID  varchar(250)    utf8_unicode_ci         No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
    Prominent   double          No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
    LatLong     point           No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
    FullTextSearch  varchar(600)    utf8_bin        No  None        Browse distinct values  Change  Drop    Primary     Unique  Index   Fulltext
With selected: Check All / Uncheck All With selected:
Print viewPrint view Propose table structurePropose table structureDocumentation
Add new fieldAdd field(s) At End of Table At Beginning of Table After
Indexes: Documentation
Action  Keyname Type    Unique  Packed  Field   Cardinality Collation   Null    Comment
Edit    Drop    PRIMARY BTREE   Yes No  BusinessID  1611454 A       
Edit    Drop    Prominent   BTREE   No  No  Prominent   0   A       
Edit    Drop    LatLong BTREE   No  No  LatLong (25)    0   A       
Edit    Drop    sx_mytable_coords   SPATIAL No  No  LatLong (32)    0   A       
Edit    Drop    FullTextSearch  FULLTEXT    No  No  FullTextSearch  0           

Note:I am not dealing with lines or polygons, only points. I need more direct samples. Also I am not interested in points within a circle. I want 20 closest points. The fact that those points are within a circle or not is irrelevant. (Actually I will use filter, however, that's latter)

user4951
  • 1.4k
  • 5
  • 20
  • 39