finding the max

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SSG001
    New Member
    • Oct 2007
    • 110

    #1

    finding the max

    I have a table as follows

    code
    PB0001AA
    PB0001AB
    PB0001AC
    PX0001AA
    PX0001AB
    PX0001AC
    PX0001AD
    PC0001AA
    PC0001AB


    I want to get data of only max
    eg in the above case
    PB0001AC
    PX0001AD
    PC0001AB







    Thanks in advance
  • SSG001
    New Member
    • Oct 2007
    • 110

    #2
    Code:
    SELECT MAX(code) FROM exmaster WHERE code IN (SELECT code FROM exmaster) GROUP BY SUBSTRING(code,1,6)
    is this ok ?
    Last edited by Rabbit; Apr 20 '13, 06:42 AM. Reason: Please use code tags when posting code.

    Comment

    • SSG001
      New Member
      • Oct 2007
      • 110

      #3
      Code:
      SELECT MAX(code) FROM exmaster WHERE GROUP BY SUBSTRING(code,1,6)
      Last edited by Rabbit; Apr 20 '13, 06:42 AM. Reason: Please use code tags when posting code.

      Comment

      • vijay6
        New Member
        • Mar 2010
        • 158

        #4
        Hey SSG001, you can use like this,

        Code:
        select MAX(Name) from Table_1 where Name like 'PB0001A%' union select MAX(Name) from Table_1 where Name like 'PX0001A%' union select MAX(Name) from Table_1 where Name like 'PC0001A%'

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          Please use code tags when posting code.

          You can do this:
          Code:
          SELECT MAX(code)
          FROM exmaster
          GROUP BY SUBSTRING(code,1,6)

          Comment

          Working...