Get only Max of each distinct?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sunilkes@gmail.com

    Get only Max of each distinct?

    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

  • Ed Murphy

    #2
    Re: Get only Max of each distinct?

    sunilkes@gmail. 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
    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.

    Comment

    • sunilkes@gmail.com

      #3
      Re: Get only Max of each distinct?

      On Nov 7, 10:10 am, Ed Murphy <emurph...@soca l.rr.comwrote:
      sunil...@gmail. 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_Num ber) AS Maxim, ItemId
      FROM tblItems
      GROUP BY ItemId

      Thanks
      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.

      Comment

      Working...