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 advanceI 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 ...|||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
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment