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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 query error

Author  Topic 

elic05
Yak Posting Veteran

62 Posts

Posted - 2011-11-28 : 20:18:51
select Id,CategoryId,VoteUntill,Question,UserName
from (
select *, seq = row_number() over (partition by CategoryId order by VoteUntill desc)
from post
)
where seq < 5

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-11-28 : 20:20:02
[code]
select Id,CategoryId,VoteUntill,Question,UserName
from (
select *, seq = row_number() over (partition by CategoryId order by VoteUntill desc)
from post
) AS d
where seq < 5
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

elic05
Yak Posting Veteran

62 Posts

Posted - 2011-11-28 : 20:22:25
greate,
thanks
even though I dont understand why,
but it works
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-11-28 : 20:23:02
the "d" is the alias name given to the derived table


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jassi.singh
Posting Yak Master

122 Posts

Posted - 2011-11-30 : 01:59:59
hi,

you are just giving alias name to a derived table

select Id,CategoryId,VoteUntill,Question,UserName
from (
select *, seq = row_number() over (partition by CategoryId order by VoteUntill desc)
from post
) AS d
where seq < 5
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-12-01 : 06:32:21
quote:
Originally posted by elic05

greate,
thanks
even though I dont understand why,
but it works



It is becuase unlike ORACLE, SQL Server needs a alias name for the derived table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -