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
 SQL Server Development (2000)
 Troublesome Query

Author  Topic 

disastor
Starting Member

2 Posts

Posted - 2005-05-12 : 13:03:33
Hi All,

I was referred to you from 4guysfromrolla web site with the hopes that you could assist me.

I currently have a 3 column table that lists customer names, street addresses and states.

I am trying to come up with a query that will pull just the top 3 customers from each state.

I've tried something like the following, but it only yields a total of 3 results:
SELECT * FROM (SELECT TOP 3(customername), state FROM table WHERE state IN (SELECT DISTINCT(state) FROM table))

Can you guys help out?
Thanks in advance.

X002548
Not Just a Number

15586 Posts

Posted - 2005-05-12 : 13:05:14
How about this

http://weblogs.sqlteam.com/brettk/archive/2005/02/10/4153.aspx



Brett

8-)
Go to Top of Page

disastor
Starting Member

2 Posts

Posted - 2005-05-12 : 13:20:00
Thank you, thank you, thank you!!!! That is exactly what I was looking for.

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-05-12 : 13:36:39
Your welcome. And Welcome to SQL Team

If you Googled

"select top n things"

You get

http://www.google.com/search?hl=en&lr=&q=select+top+n+things

the third link is funny though...aint it



Brett

8-)
Go to Top of Page
   

- Advertisement -