Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the equivalent function in Oracle for IF function in MySQL?

so I have this function in mysql syntax(on a mysql DB) that I’m trying to run on Oracle and can’t seem to find the similar function in Oracle for MYSQL "IF".

SELECT 
table1.PROJECT_ID
max(if(Table2.Typ = 'progress', 'progress',NULL)) AS 'progress',
max(if(Table2.Typ = 'acquired', 'acquired',NULL)) AS 'acquired'
FROM Table1
LEFT JOIN Table2 ON Table2.Name = Table1.Item_Description
GROUP BY PROJECT_ID;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Use a CASE expression (which is in the ANSI standard):

SELECT table1.PROJECT_ID,
       max(CASE WHEN Table2.Typ = 'progress' THEN 'progress' ELSE NULL END) AS progress,
       max(CASE WHEN Table2.Typ = 'acquired' THEN 'acquired' ELSE NULL END) AS acquired
FROM   Table1
       LEFT JOIN Table2 ON Table2.Name = Table1.Item_Description
GROUP BY PROJECT_ID;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading