0

I have a table "rdv" like this
table

I want to select all the rows of the lastest date, in this case, the 3 rows of 2017-04-29, I tried the query from Get the latest date from grouped MySQL data, but it can only select the last one rows
one rows selected
So how to select all the rows of the lastest date?

Community
  • 1
  • 1
Jiang Lan
  • 171
  • 1
  • 12

3 Answers3

1

The issue is with the condition. You need to change the datetime to date

select *
from rdv
where date (date_creation) in (
        select date (max(date_creation))
        from rdv
        )
Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76
Agam Banga
  • 2,708
  • 1
  • 11
  • 18
0

Use DATE function to get only date of timestamp and CURDATE function to get current date

SELECT * FROM table WHERE DATE(date_field) = CURDATE()

0

use this

select * from rdv having date_creation in (select max(date_creation) from rdv)

or try this

    select * from rdv having date_creation = (select max(date_creation) from rdv)
Anshul
  • 103
  • 9
  • I tried this but it returns the same single row, I know now, need to convert the Datetime to Date, this will work, `SELECT * FROM rdv WHERE DATE(date_creation) IN (SELECT DATE(max(date_creation)) FROM rdv)` – Jiang Lan May 06 '17 at 17:55
  • Please tell me if it Works – Anshul May 06 '17 at 18:02
  • @ Anshul I tried your query but it returns only one row cause it's the max datetime, so I convert it to date, I add DATE base on your query, then it works `select * from rdv having DATE(date_creation) in (select DATE(max(date_creation)) from rdv)` – Jiang Lan May 06 '17 at 18:08