Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Select Top 10 Query


Select Top 10 Query

Author
Message
justfillingtime
justfillingtime
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 77
Hi All,

Got a quick Select Top 10 question. I'm running a simple query to find top ten people who have contacted us in the past month.

The problem is that it's only counting the top 10 distinct people, I want to include rows 11-13 in my count as these people have contated the same amout of times as Cust20 in Row 10.

Row Count Cust ID
1 64 Cust11
2 24 Cust12
3 21 Cust13
4 16 Cust14
5 14 Cust15
6 12 Cust16
7 11 Cust17
8 11 Cust18
9 11 Cust19
10 10 Cust20
11 10 Cust21
12 10 Cust22
13 10 Cust23


Hope that makes sense!
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16580 Visits: 17023
justfillingtime (5/13/2013)
Hi All,

Got a quick Select Top 10 question. I'm running a simple query to find top ten people who have contacted us in the past month.

The problem is that it's only counting the top 10 distinct people, I want to include rows 11-13 in my count as these people have contated the same amout of times as Cust20 in Row 10.

Row Count Cust ID
1 64 Cust11
2 24 Cust12
3 21 Cust13
4 16 Cust14
5 14 Cust15
6 12 Cust16
7 11 Cust17
8 11 Cust18
9 11 Cust19
10 10 Cust20
11 10 Cust21
12 10 Cust22
13 10 Cust23


Hope that makes sense!


You can use "WITH TIES".


Select top 10 WITH TIES [Columns]
From YourTable
Order by Something



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
justfillingtime
justfillingtime
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 77
BOOM! Thanks Sean Lange. Sorted.
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16580 Visits: 17023
justfillingtime (5/13/2013)
BOOM! Thanks Sean Lange. Sorted.


You're welcome. Glad that worked for you.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search