I want to return the date and ID for the latest added record in on of our tables. can anyone suggest right query for that plz. We are using sqlServer
SELECT [BGArx_ID], [BGArx_PUBLISHED_DATE]
FROM TECH_ARTICLES
WHERE [BGArx_PUBLI开发者_如何学编程SHED_DATE] = ???
Use the ORDER BY clause to sort by the newest record and then limit the query to return just one result.
SELECT BGArx_ID, BGArx_PUBLISHED_DATE
FROM TECH_ARTICLES
ORDER BY BGArx_PUBLISHED_DATE DESC LIMIT 1;
EDIT (marc_s)
for SQL Server, which doesn't know the LIMIT
keyword, you'd need to use TOP 1
in the select instead:
SELECT TOP 1 BGArx_ID, BGArx_PUBLISHED_DATE
FROM TECH_ARTICLES
ORDER BY BGArx_PUBLISHED_DATE DESC
精彩评论