• 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.

    RowCount Cust ID

    164 Cust11

    224 Cust12

    321 Cust13

    416 Cust14

    514 Cust15

    612 Cust16

    711 Cust17

    811 Cust18

    911 Cust19

    1010 Cust20

    1110 Cust21

    1210 Cust22

    1310 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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/