Results 1 to 3 of 3

Thread: functions

  1. #1
    Join Date
    Dec 2002
    Posts
    9

    Unanswered: functions

    I need to do a LEAST() and Greatest() function in SQL query.

    Is this possible in anyway shape or form?

    Here is an example...

    tblTable.oneID = 4
    tblTable.twoID = 5


    SELECT ... LEAST(tblTable.oneID,tblTable.twoID) FROM tblTable

    and it returns 4. Or in the GREATEST function, it would return 5.

    Please help.

    Thanks in advance

  2. #2
    Join Date
    Dec 2002
    Posts
    9
    I think i figured it out...


    LEAST function = SELECT (CASE WHEN oneID < twoID THEN oneID ELSE twoID) as LeastOFtheTWO FROM ...

    GREATEST function = SELECT (CASE WHEN oneID > twoID THEN oneID ELSE twoID) as LeastOFtheTWO FROM ...

  3. #3
    Join Date
    Feb 2002
    Posts
    2,232
    You are on the right track. Try the following for the least case:

    select case when (a < b) then a else b end
    from (select min(field1) as a, min(field2) as b from table) as abc

Posting Permissions

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