I would like to have a row number column in a select table output, but when I try using the ROW_NUMBER() function MariaDB throws a syntax error. There are several references on
Window functions are supported in MariaDB 10.2 or higher version only.
MariaDB 10.2 or higher:
SELECT
MyData.*,
ROW_NUMBER() OVER ( ORDER BY ID ) as Therow
FROM MyData
WHERE Date_Reading > Now()- INTERVAL 3 HOUR;
For lower version:
We can use the MySQL variable to do this job.
SELECT
MyData.*,
@row_num:= @row_num + 1 AS Therow
FROM
MyData,
(SELECT @row_num:= 0 AS num) AS c
WHERE Date_Reading > Now()- INTERVAL 3 HOUR
ORDER BY test.`date` ASC;