开发者

How to get latest record date from column

开发者 https://www.devze.com 2022-12-14 00:22 出处:网络
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

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

精彩评论

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

关注公众号