Summary -

In this topic, we described about the Conditional Expressions with detailed example.

Conditional Expressions in SQL are used to evaluate conditions based on the input values. Conditional Expressions that are used in SQL are CASE, DECODE, COALESCE, NULLIF, IFNULL, IN. Conditional Expressions works on the conditions.

Syntax for CASE statement –

CASE
       WHEN condition1 THEN result1
       WHEN condition2 THEN result2
       WHEN conditionN THEN resultN 
       ELSE result
END;   

Syntax for IF NULL –

IF NULL(expression1, expressio2|value) FROM table; 

Syntax for NULL IF–

SELECT NULLIF(Expression1, Expression2) from table; 

Syntax for DECODE –

DECODE(expression, searchvalue1,result1,searchvalue2,result2,….
DEFAULT VALUE)  

Syntax for IN –

IN(expression1, expression) FROM table; 

Syntax for COALESCE –

SELECT  COALESCE(expression1, expression2|Value) FROM table; 

We have discussed about each function in detail in the previous topics.