In MySQL 8.0
, you can use a great function called ROW_NUMBER()
.
However, after creating a database query that works nicely in MySQL 8.0
that uses ROW_NUMBER()
, I see that the server that I'm using has MySQL 5.7
and I was told I can't upgrade it to MySQL 8.0
.
Are there any easy ways to translate ROW_NUMBER()
from MySQL 8.0
into syntax with the same functionality for MySQL 5.7
, specifically for my case? I checked a few other translations and for my case and they didn't work.
My query is below and here is a link to the fiddle for a demo
SELECT *
FROM
(
SELECT *, ROW_NUMBER() OVER(PARTITION BY website ORDER BY id ASC) AS r_num
FROM sites
) AS t
WHERE t.r_num < 4
ORDER BY t.datePub ASC;