Highest value from a column

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • student_help
    New Member
    • Aug 2006
    • 5

    Highest value from a column

    Hi

    I need assistance. I have a column which can have random length but I need to find the highest value in this column. e.g. the Column could contain ABC1234 and ABC125 and I need to find the MAX value in this column which in this case would be ABC1234. I have tried the MAX(column_tabl e) but it was returning ABC125 as the highest value (I am guessing it was adding a zero to the end).

    Would someone be able to point me in the direction of finding a solution to this problem?

    Thank you for your time. please let me know if you have any questions.
  • Newface
    New Member
    • Feb 2012
    • 16

    #2
    Select top 1 [column_table]
    from [table_name]
    group by [column_table]
    order by [max(len([column_table]))] desc



    Note:Please use Rownum in place of top if using oracle after where clause.
    Last edited by Newface; Feb 8 '12, 08:22 PM. Reason: Note Addition

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Define max. Z0 is bigger than all the ones in your example if you're looking at ASCII value. AAAAAAAAAA00000 00 is bigger if you're looking at length. Without a clear definition, we can't help you.

      Comment

      • student_help
        New Member
        • Aug 2006
        • 5

        #4
        It turned out the query was returning me the correct result - it was a join which was being used at a later stage in the query which was causing the issue.

        Apologies for wasting your time - this is the joy of working with code that has no comments or documentation anywhere in it.

        Thank you very much for your replies and help

        Comment

        Working...