January 26, 2009 at 5:51 pm
Hi there
Could u pls help to achieve this. This is not simple as u guys think pls send me the query instead os telling its simple
i need top version on each id as a result
ORIGINAL DATA
id version text age sex
1 1 aa 1 M
1 2 bb 2 M
1 3 cc 1 M
2 1 dd 3 M
3 1 ee 4 M
3 2 ff 1 F
RESULT
ID VERSION text age sex
1 3 cc 1 M
2 1 dd 3 M
3 2 ff 1 F
Cheers
January 26, 2009 at 6:41 pm
sqlcool (1/26/2009)
Hi thereCould u pls help to achieve this.
i need top version on each id as a result
ORIGINAL DATA
id version
1 1
1 2
1 3
2 1
3 1
3 2
RESULT
ID VERSION
1 3
2 1
3 2
Cheers
Be more than glad to help, once you show us what you have tried so far. Has something to do with fish...
January 26, 2009 at 6:42 pm
Two possible answers, both will work:
TOP
ROW_NUMBER
----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software
January 26, 2009 at 7:09 pm
Lynn Pettis (1/26/2009)
Be more than glad to help, once you show us what you have tried so far. Has something to do with fish...
Mmm, learning you are... 🙂
David
@SQLTentmaker“He is no fool who gives what he cannot keep to gain that which he cannot lose” - Jim Elliot
January 26, 2009 at 7:12 pm
hmmm, yes. Simple ones too easy to just give away.
January 26, 2009 at 7:47 pm
Grant Fritchey (1/26/2009)
Two possible answers, both will work:TOP
ROW_NUMBER
Simple MAX would do it...
--Jeff Moden
January 26, 2009 at 9:15 pm
Think, actually a GROUP BY with MAX in SELECT, hmmm
January 26, 2009 at 9:21 pm
Jeff Moden (1/26/2009)
Grant Fritchey (1/26/2009)
Two possible answers, both will work:TOP
ROW_NUMBER
Simple MAX would do it...
Simple isn't nearly as much fun. Small data set, ROW_NUMBER may perform better.
----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software
January 26, 2009 at 9:49 pm
sqlcool (1/26/2009)
Hi thereCould u pls help to achieve this.
i need top version on each id as a result
ORIGINAL DATA
id version
1 1
1 2
1 3
2 1
3 1
3 2
RESULT
ID VERSION
1 3
2 1
3 2
Cheers
select
from
group by
Nothing fancy.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply