Consider a MySQL table with a datetime field. I would like to select the row with the furtherest time between it to between the next or previous datetime values. For example, if there exist records with the following values:
1 2012-10-17 12:00
2 2012-10-16 12:00
3 2012-10-14 12:00
4 2012-10-08 12:00
5 2012-10-03 12:00
6 2012-10-01 12:00
Therefore the most “isolated” record is record #4 as it is 5 days away from the nearest record.
Note that there may or may not be ties for “most isolated”, in this case any of the tying rows may be returned, or all of them. Also, although the example shows the records with datetime values sequentially ordered, that may not necessarily be true in the real data set.
You can use this to determine distance to the closest records:
You can get the farthest of these values fairly easily.