dbTalk Databases Forums  

Get only Max of each distinct?

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Get only Max of each distinct? in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
sunilkes@gmail.com
 
Posts: n/a

Default Get only Max of each distinct? - 11-07-2007 , 03:49 AM






Hello,

I have a table

ItemID Version

12 1.0
12 1.1
12 2.0
13 2.0
13 1.0
14 1.0
15 1.0
15 5.0
15 2.1

How do I write a Select query to get me all distinct item IDs, whichm
are of the latest version?

Like this:

ItemID Version
12 2.0
13 2.0
14 1.0
15 2.1

Any help would be appreciated.

Thanks


Reply With Quote
  #2  
Old   
Ed Murphy
 
Posts: n/a

Default Re: Get only Max of each distinct? - 11-07-2007 , 04:10 AM






sunilkes (AT) gmail (DOT) com wrote:

Quote:
I have a table

ItemID Version

12 1.0
12 1.1
12 2.0
13 2.0
13 1.0
14 1.0
15 1.0
15 5.0
I assume 5.0 is a typo for 2.0
15 2.1

How do I write a Select query to get me all distinct item IDs, whichm
are of the latest version?

Like this:

ItemID Version
12 2.0
13 2.0
14 1.0
15 2.1
This smells like homework. Look up MAX() and GROUP BY.


Reply With Quote
  #3  
Old   
sunilkes@gmail.com
 
Posts: n/a

Default Re: Get only Max of each distinct? - 11-07-2007 , 05:35 AM



On Nov 7, 10:10 am, Ed Murphy <emurph... (AT) socal (DOT) rr.com> wrote:
Quote:
sunil... (AT) gmail (DOT) com wrote:
I have a table

ItemID Version

12 1.0
12 1.1
12 2.0
13 2.0
13 1.0
14 1.0
15 1.0
15 5.0

I assume 5.0 is a typo for 2.0

Got it, actually it was pretty simple, was trying it incorrectly
earlier !

SELECT MAX(Version_Number) AS Maxim, ItemId
FROM tblItems
GROUP BY ItemId

Thanks

Quote:
15 2.1


How do I write a Select query to get me all distinct item IDs, whichm
are of the latest version?

Like this:

ItemID Version
12 2.0
13 2.0
14 1.0
15 2.1

This smells like homework. Look up MAX() and GROUP BY.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.