Joining two tables by the nearest match
I want to join the left table with the "nearest" row in the right table. 


This is a KNN problem. For it you'll likely want a real database. I highly suggest you migrate to PostgreSQL and use PostGIS, where this can be solved using an index. Your answer has 0 to do with your problem. Your question is,


  by the nearest match


Your answer is only looking at one way directionality, and it's only doing it for one row not a set: it's a correlated sub-query. You simply need to change course, or bounty a developer to include KNN in MySQL. MySQL is using Boost for GIS, so maybe someday someone will jump nearest(Point const &amp;, unsigned) in the code base. I checked for ya, it's not there and there is no professional way to do what you want at any scale.

MySQL's GIS offering is the worst out of all the majors players. No one uses it. To give you an idea of scale,


MySQL has 225 questions on GIS.SE.
PostGIS has 5,771


It's a marketing point to say it supports a spatial index. See also


PostgreSQL vs. MySQL: spatial feature comparison


BTW, PostGIS also supports KNN on timestampg using btree_gist