I've got a simple table below,
Select * from message_log where Message = 'BUILD' order by 1;
+------------+-------------+
| **Message | Log** |
+------------+-------------+
| Build | Day Start |
+------------+-------------+
| Build | Day End |
+------------+-------------+
| Build | Dusk Start |
+------------+-------------+
| Build | Dusk End |
+------------+-------------+
| Build | Night Start|
+------------+-------------+
| Build | Night End |
+------------+-------------+
If I for example write a CASE statement
SELECT DISTINCT CASE WHEN (Log = 'Day Start') THEN 'RUNNING' END AS A
from message_log where Message = 'BUILD' order by 1;
It'll return a Null value and a 'RUNNING' value, can I write this in such a way that it doesn't include the null row?
Best Answer
Just add a
WHERE
condition. And if you are only displaying one value,RUNNING
, then there is no reason for aCASE
. Otherwise you will want to evaluate each condition in theCASE
including what should display in the event none of the conditions is met; a default value.So here is the code to your original question:
And here is the code for a multi-condition
CASE
: