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 2000 Forums
 Transact-SQL (2000)
 Selecting out of a selected result

Author  Topic 

ten2the6
Starting Member

7 Posts

Posted - 2004-10-04 : 13:31:47
I want to select records out of another selected results. Here is my problem

select top 1 visitor_browser, count(*) as number
from di_web_sessions
group by visitor_browser
order by number desc

returns

visitor_browser | number
-----------------------------------
IE6                 | 41

Now I just want the first column to be returned so I tried..

Select visitor_broser
FROM
(select top 1 visitor_browser, count(*) as number
from di_web_sessions
group by visitor_browser
order by number desc)


This should return just 'IE6' but does not work!

Can this be done? If so, how?

I do not want to use Temp tables or cursors.

Please advise,

Thanks in advance

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-10-04 : 13:35:40
What you are trying to accomplish can be performed is this manner:
select top 1 visitor_browser
from di_web_sessions
group by visitor_browser
order by count(*) desc
As far as "selecting from a select", it is referred to as a derived table and must be aliased
Select visitor_broser 
FROM
(select top 1 visitor_browser, count(*) as number
from di_web_sessions
group by visitor_browser
order by number desc) dt
Go to Top of Page

ten2the6
Starting Member

7 Posts

Posted - 2004-10-04 : 13:59:33
Thank you, the alias name was the missing link!

I love this forum!!!
Go to Top of Page
   

- Advertisement -