开发者

SQL Select latest post by postID

I am wanting to display in the footer when the most recent message wa开发者_StackOverflows posted. eg: last post Saturday, 23 July 2011 03:02 p.m.

I am using ASP.Net 4.0, Visual Studio and MSSQL Server Management Studio.

Sql Tables

postID | postCreated

19 | Saturday, 23 July 2011 01:02 p.m.

20 | Saturday, 23 July 2011 02:02 p.m.

21 | Saturday, 23 July 2011 03:02 p.m.

postID is Int and is set as the primary key, and auto increments. postCreated is Varchar.

What I have tried so far

SELECT max(postID) from "Table"

this shows me the most Recent postID, but I want to extend this to grab the most recent postCreated associated to that ID

Any help would be greatly appreciated.

Cheers


SELECT TOP 1 * FROM Table ORDER BY postID DESC


Try this sql query:

 SELECT * FROM Table WHERE postID = (SELECT max(postID) from Table)


select top 1 * from Table t order by t.postID desc


  Select tn.postCreated
    From table_name tn
   Where tn.postId = 
          (Select Max(postId)
             From table_name);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜