Reputation: 3329
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?
Upvotes: 1
Views: 478
Reputation: 6232
If publishdate is datetime
SELECT TOP 1 *
FROM tbl
ORDER BY publishdate DESC
Upvotes: 0
Reputation: 73604
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.
Upvotes: 3
Reputation: 89741
SELECT * FROM tbl WHERE publishdate = (SELECT MAX(publishdate) FROM tbl)
Upvotes: 4