Doubt on query

  • I have an table having 2 columns with values like,

    CountName

    11111

    22222

    23333

    Now, I need an result like, given below. if there is duplicate in Count column, then in result, give only the Name column having higher value

    CountName

    11111

    23333

  • SELECT [Count], MAX(Name)

    FROM tbl

    GROUP BY  [Count]

    Or, if you want more data on the same row:

    ; WITH CTE AS (

    SELECT *, rowno = row_number() OVER(PARTITON BY [Count] ORDER BY Name DESC)

    FROM tbl

    )

    SELECT *

    FROM CTE

    WHERE rowno = 1

    Note that this forum is for security-related questions, for which your post does not seem to qualify.

    [font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]

  • Worked like charm. thanks.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply