Get nearest datetime from another table

75 views Asked by At

I want to join table 1 with table 2 with nearest time table 1 X table 2.

table 1:

datetime 1      
-----------------------
2016-01-12 10:00:00

table 2:

datetime 2
-----------------------
2016-01-12 10:40:00
2016-01-12 09:30:00
2016-01-12 12:00:00

the nearest time is "2016-01-12 09:30:00" from datetime 1 - table 1...

I tried:

SELECT * FROM table_1 JOIN table_2
WHERE datetime_1 > now();
0

There are 0 answers