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 2005 Forums
 SQL Server Administration (2005)
 Order results

Author  Topic 

beza
Starting Member

16 Posts

Posted - 2009-02-26 : 09:37:54
I have a table with a userName and counter fields
What I want to do is select the 20 record sets which have the biggest counters and then order those results by abc (userName will go by abc) I tried doing it with order by but I can't seem to do it

Can anyone help ??

Thanks a lot!!

heavymind
Posting Yak Master

115 Posts

Posted - 2009-02-26 : 09:55:22
please show us the query you already have...

Thanks, Vadym
MCITP DBA 2005/2008
Chief DBA at http://www.db-staff.com
Go to Top of Page

beza
Starting Member

16 Posts

Posted - 2009-02-26 : 10:06:06
my query goes like this

SELECT TOP 10 Users.UsersName, Users.Counter
FROM Users
ORDER BY Counter DESC, UsersName ASC

I want to select from table users, the userName and counter
ordered by counter first and than order those resuls by abc

for example

UserName Counter
a 1
b 2
c 3
d 4

when I select top 2 I will get
c and afterwards d

Thanks a lot for you help
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-02-26 : 10:12:08
Your query looks ok to me. Whats the output you are getting ?
Go to Top of Page

beza
Starting Member

16 Posts

Posted - 2009-02-26 : 10:24:16
I get it sorted only by abc
and I have no idea why

I need to select TOP 10 records ordered by counter and then do some kind of inner sort for those 10 records

Thank for you help
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-26 : 11:24:43
Maybe clear if you post sample data and expected output?
Go to Top of Page

beza
Starting Member

16 Posts

Posted - 2009-02-26 : 19:34:35
I did!

look 2 posts above

Thanks
Go to Top of Page
   

- Advertisement -