Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Doubt on query Expand / Collapse
Author
Message
Posted Wednesday, May 21, 2014 7:46 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 9:30 AM
Points: 403, Visits: 982
I have an table having 2 columns with values like,

Count Name
1 1111
2 2222
2 3333

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

Count Name
1 1111
2 3333
Post #1573170
Posted Wednesday, May 21, 2014 7:52 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 7:07 AM
Points: 803, Visits: 720
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.


Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Post #1573176
Posted Thursday, May 22, 2014 2:57 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 9:30 AM
Points: 403, Visits: 982
Worked like charm. thanks.
Post #1573467
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse