Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Querry Help

Author  Topic 

komeltschenko
Starting Member

4 Posts

Posted - 2011-02-02 : 12:18:07
I have a table with blog entries from all blogs.
I have 4 different blogs(BlogID 1-4)
I am trying to get the most recent (by date) blog entries 1 for each BlogID.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-02-02 : 12:46:31
select Col1, Col2, ...
from
(select row_number() over (partition by BlogID order by dateCol desc) as rownum,* from yourTable)dt
where rownum=1


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

komeltschenko
Starting Member

4 Posts

Posted - 2011-02-02 : 13:17:48
SELECT strBlogEntryTitle, StrBlogEntrySummary, dtmBlogEntryUpdated
FROM
(SELECT row_number() over (partition by intBlogID ORDER BY dtmBlogEntryUpdated DESC) as rownum, * from TBlogEntries)dt where ronum=1

Gives error:Msg 207, Level 16, State 1, Line 10
Invalid column name 'ronum'.
Go to Top of Page

komeltschenko
Starting Member

4 Posts

Posted - 2011-02-02 : 13:18:46
opps rownum
Go to Top of Page

komeltschenko
Starting Member

4 Posts

Posted - 2011-02-02 : 13:21:48
It worked thank you sehr viel
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-02-02 : 13:40:09
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -