Skip to content
Advertisement

Can we write case statement without having else statement

I have this query:

It is giving me o/p as

Id
A
B
NULL
NULL
NULL

I don’t want to have NULL values in my output, I only want to compare in A and B, is it possible in case statement.

Advertisement

Answer

A case expression can only manipulate the value of an expression, not remove rows from the result. If you want to omit the nulls from the result, you’ll have to add a where clause:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement