DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: How to select the maximum value in a record among columns?

  1. #1
    Join Date
    Feb 2002
    Posts
    48

    Lightbulb How to select the maximum value in a record among columns?

    Hi,

    I have a table with columns e.g. columnA (default to 1), columnB (default to 2), columnC (default to 3), columnD (default to 4), and another column named HIGHEST_VALUE. Column A, B, C or D is nullable column.

    What is the best way to obtain the maximum value among columnA to D and populate this maximum value in HIGHEST_VALUE column. I understand MAX( ) function can be used but it is more for getting maximum value among records, not within one single record.

    Any suggestions or comments would be greatly appreciated.

    Thanks in advance!

  2. #2
    Join Date
    Feb 2004
    Posts
    77
    select greatest(a, b, c, d) from your_table;

  3. #3
    Join Date
    Feb 2002
    Posts
    48
    Thank you for the information!

  4. #4
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    Why would you want to store (and maintain) the highest value, when it can simply be calculated dynamically?
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width