Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Posts
    2

    Unanswered: Comparing two Columns

    I know this is a stupid question, but I'm unable to find an answer...

    I'm trying to compare two columns and return the smaller record of the two. There's an Oracle function called Least() that does this, but I've found nothing for db2.

    Here's an example of the Oracle function:
    SELECT LEAST(SYSDATE, table.date) FROM table

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: Comparing two Columns

    select col0,
    case(when col1<col2 then col1 else col2 end)
    from table1 ;

    Or write a UDF which does the same ....

    Alternately, if this very often required, you may add a column which is generated always as the minumum of the two columns


    Cheers

    Sathyaram

    Originally posted by Agent Hubcap
    I know this is a stupid question, but I'm unable to find an answer...

    I'm trying to compare two columns and return the smaller record of the two. There's an Oracle function called Least() that does this, but I've found nothing for db2.

    Here's an example of the Oracle function:
    SELECT LEAST(SYSDATE, table.date) FROM table
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    Jul 2003
    Posts
    2

    Re: Comparing two Columns

    Originally posted by sathyaram_s
    select col0,
    case(when col1<col2 then col1 else col2 end)
    from table1 ;

    Or write a UDF which does the same ....

    Alternately, if this very often required, you may add a column which is generated always as the minumum of the two columns


    Cheers

    Sathyaram
    Thanks for the reply! I had to remove the ( and ) to get it to run properly, though.

Posting Permissions

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