how to display repeated rows on top?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rohan S

    #1

    how to display repeated rows on top?

    Hi,

    I want a help in sql server 2005 as mentioned below:

    I want to select rows on top from a table which has more repeated values in a column.

    For Example:
    pEnt_ID ShortName FundID Received Date
    ---------------------------------------------------------------
    58731 M IX A-3 NULL NULL
    58729 M IX A-1 4 NULL
    58730 M IX A-2 4 NULL
    58729 M IX A-1 23772 NULL
    58730 M IX A-2 23772 09/08/2010
    58729 M IX A-1 4 NULL

    I want to display the rows which has maximum repeated value in pEnt_ID column ie. 58729 on top and then so on.

    Like this:

    pEnt_ID ShortName FundID Received Date
    ---------------------------------------------------------------
    58729 M IX A-1 4 NULL
    58729 M IX A-1 4 NULL
    58729 M IX A-1 23772 09/07/2010
    58730 M IX A-2 4 NULL
    58730 M IX A-2 23772 09/08/2010
    58731 M IX A-3 NULL NULL

    Please provide some query solution.

    Thanks,
    Rohan
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    What if your data look like this:

    pEnt_ID ShortName FundID Received Date
    -------------------------------------------------------------
    58731 M IX A-3 NULL NULL
    58732 M IX A-1 4 NULL
    58730 M IX A-2 4 NULL
    58732 M IX A-1 23772 NULL
    58730 M IX A-2 23772 09/08/2010
    58732 M IX A-1 4 NULL
    58732 M IX A-1 4 NULL
    58731 M IX A-3 NULL NULL
    58729 M IX A-1 4 NULL
    58729 M IX A-1 4 NULL
    58729 M IX A-1 4 NULL

    How would your result look like?

    ~~ CK

    Comment

    Working...