Select Last N days data based on datetime column

I have datetime column and its values are like below

2021-04-13 15:31:59
2021-04-13 15:29:59
2021-04-12 15:31:59
2021-04-12 15:29:59
2021-04-10 15:31:59
2021-04-10 15:29:59
2021-04-8 15:31:59
2021-04-8 15:29:59

I want to select the last 3 days data available in table

In above example it is 2021-04-10 , 2021-04-12 and 2021-04-13

I tried something like below

SELECT * FROM `table` WHERE DATE(`timer`) >= DATE(NOW()) - INTERVAL 3 DAY 

But its returning data from 2021-04-12 , since there is no data available from 2021-04-11.

Answer

In MariaDB 10.2.32 you can use DENSE_RANK() window function:

SELECT *
FROM (
  SELECT *, DENSE_RANK() OVER (ORDER BY DATE(timer) DESC) rnk
  FROM tablename
) t
WHERE rnk <= 3

See a simplified demo.