say i have a table
say, the expected result here is Get distict top 5 char’s in the order of Value
select top 5 distict char from (select char from table order by pkey)temp
— Error : Order By should not be part of SubQuery
— Reason: Why we use subquery : to be source of outer clause.
To Do :
***** Lets try it out by Top Clause
select top 5 disctinct from (select top 100 percent char from table order by value)temp *Here inner query is accepted for having ‘Order By’ since it is a helper to TOP clause Since we specify 100 percent, inner results are not Ordered actually. –WorkAround : we can use top 99.99 percent to enforce order by, but the no of result set records varies, so this solution is not at all recomended.
Happy Reading 🙂
I am so happy that i reached 50th post 🙂