简体   繁体   中英

How to find last date all record in MySQL?

how can i find last date record in MySQL. i have this current date record but if i want to get a data of last day (not yesterday). it is possible to get last date of record in MySQL.

my current date record are there (28-11-2017).. and i want last date of record which is (25-11-2017) between this 25 to 28 there is no data . i want this last date record.

ex.

id       DATE      PRODUCT_ID
1    2017-11-25      11
2    2017-11-25      12
3    2017-11-24      6

so last date in my table will be 25. how can i get all record of that date.

link for current date table: current table

One option is to compare the date of each record against a non correlated subquery which finds the most recent date in the table.

SELECT *
FROM yourTable
WHERE DATE = (SELECT MAX(DATE) FROM yourTable);

If you are certain that there is only one latest date, or you can live with just a single record in the event of ties, then MySQL offers an even simpler option:

SELECT *
FROM yourTable
ORDER BY DATE DESC
LIMIT 1;
SELECT DATE FROM your_table ORDER BY id DESC LIMIT 1

这将为您提供最后的约会。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM