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
 select top 50 records

Author  Topic 

shajimanjeri
Posting Yak Master

179 Posts

Posted - 2007-10-04 : 03:46:01
Hi,
How to write a query to get top 50 distinct records from a table.
I mean I have a table 'C1_Subscribers' with a field name 'Nickname'. Here I need to select top 50 non-repeated nickname only.

Can anybody can help me!!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-04 : 03:48:24
TOP 50 ordered by what?
SELECT DISTINCT TOP 50 NickName
FROM C1_Subscribers



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2007-10-04 : 03:53:10
This is one way:
SELECT TOP 50 NickName
GROUP BY NickName

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com/SQL
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-04 : 05:12:30
Top without order by doesnt make any sense until you want them random

other method

Set Rowcount 50
Select query
Set Rowcount 0


Madhivanan

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

- Advertisement -