If you are only looking for the difference between two rows, you can reference them by their ids.
SELECT TIMESTAMPDIFF(MICROSECOND, s1.date, s2.date) DIV 1000 FROM via1 s1 , via1 s2 WHERE s1.id = 1 AND s2.id = 2 ; There are a few errors in your CREATE TABLE statement:
CREATE TABLE via1 ( id int auto_increment primary key, sensor varchar(10) NOT NULL, date timestamp(6) default current_timestamp(6) ); You're using an old version of MySQL (5.5.44). From the docs:
11.3.6 Fractional Seconds in Time Values - MySQL 5.6 Reference Manual
Before MySQL 5.6.4, the instances are limited in which a fractional seconds part is permitted in temporal values. ...when MySQL stores a value into a column of any temporal data type, it discards any fractional part and does not store it.