Home » SQL & PL/SQL » SQL & PL/SQL » Conditional Selection of a Field
Conditional Selection of a Field [message #578347] Wed, 27 February 2013 03:44 Go to next message
supraj
Messages: 2
Registered: February 2013
Junior Member
I'd like to select one of two fields from a table, based on which of them is greater for that row.

eg. For every row in JOINING_TBL, I'd like to select either JOINING_DATE or REJOINING_DATE, whichever is greater. I do dream about being able to use a Java-like ternary operator in here, something like this:-
SELECT (JOINING_DATE>REJOINING_DATE?JOINING_DATE:REJOINING_DATE) FROM JOINING_TBL

However, I understand(through other fora) that this can't be used in here. Could someone help me with approaching this scenario? I'm relatively new to this, so please pardon my ignorance in the issue.
Re: Conditional Selection of a Field [message #578351 is a reply to message #578347] Wed, 27 February 2013 03:55 Go to previous messageGo to next message
Littlefoot
Messages: 19524
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
GREATES function might be what you are looking for:
select greatest(joining_date, rejoining_date) 
from joining_tbl
Re: Conditional Selection of a Field [message #578357 is a reply to message #578347] Wed, 27 February 2013 04:29 Go to previous messageGo to next message
delna.sexy
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
You can use CASE statement or GREATEST function as said by Littlefoot.

regards,
Delna
Re: Conditional Selection of a Field [message #578432 is a reply to message #578357] Thu, 28 February 2013 00:55 Go to previous message
supraj
Messages: 2
Registered: February 2013
Junior Member
Thanks a lot Littlefoot( and Delna)! That worked! Smile
Previous Topic: Join help needed
Next Topic: SQL Model Clause , Please Help
Goto Forum:
  


Current Time: Fri Aug 29 05:49:25 CDT 2014

Total time taken to generate the page: 0.13689 seconds