简体   繁体   中英

SQL date compare

I have a table with 1000 records. One column is the publish date which takes the format '2008-01-02 00:00:00.000' . I want to query the SQL DB to get the record with the latest publish date. should i just do a compare or there is some other filter?

SELECT * FROM tbl WHERE publishdate = (SELECT MAX(publishdate) FROM tbl)

If you want just one record:

SELECT TOP 1 * FROM mytable ORDER BY publishdate DESC

If you want ALL books with the highest publish date, use Cade Roux's query.

If publishdate is datetime

SELECT TOP 1  *
FROM tbl
ORDER BY publishdate DESC

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