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.
| Author |
Topic |
|
iminore
Posting Yak Master
141 Posts |
Posted - 2005-09-29 : 04:49:01
|
| This is n odd request in that something works - but I can't remember why.This statement:select top 20 userid from (select top 20 userid from KATUsers order by userid)aref order by userid desc What is the role of 'aref' ? And where would I find a reference to it in Books Online? |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2005-09-29 : 04:52:25
|
aref is actually the name you are aliasing your subquery with ie the code between "()".I bet this also works: select top 20 userid from (select top 20 userid from KATUsers order by userid) xref order by userid descDuane. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-29 : 05:00:52
|
| It is the alias name of the subquery so that that subquery will be treated as a seperate tableMadhivananFailing to plan is Planning to fail |
 |
|
|
iminore
Posting Yak Master
141 Posts |
Posted - 2005-09-29 : 05:04:04
|
| Agreed the alias can be called anything. I'm just not clear why SQL needs an alias (you get an error without it), but thanks for the help. BO has much about aliases and subqueries. |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2005-09-29 : 05:12:17
|
>> I'm just not clear why SQL needs an alias Quite simple really - as madhivanan said - it is treated as a seperate table - so it therefore needs to have a name.What if there are more than one subqueries in a sql statement?Duane. |
 |
|
|
|
|
|