Lets say that I have a table with a timestamp column full of records and I want to calculate the smallest time difference between two consecutive records using only one query.
Maybe a table like…
CREATE TABLE `temperatures` (
`temperature` double,
`time` timestamp DEFAULT CURRENT_TIMESTAMP
);
Assuming that there is a unique constraint on the time stamp (to prevent there being two recordings at the same time):
This answers the questions rather precisely – and doesn’t convey other useful information (such as which two timestamps or temperatures).