开发者

How to get latest record date from column

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜