Reputation: 613
I have a basic question. I want to return data from my table when the condition is true but when it is not I got the null row, but I don't want that.
This is my example:
select case when coalesce(var, '') != '' then (select id from user) end
when var is not '' I got data, bat, when is not I, got null
Upvotes: 0
Views: 1187
Reputation: 1269445
You seem to be asking for:
select id
from "user"
where var <> '';
You don't need to handle NULL
s as a special case, because <>
will not return any rows when var
is NULL
.
Upvotes: 0
Reputation: 1790
I think you simply just need to filter out your NULL
s returned in a where
clause:
select coalesce(var, id)
from user
where coalesce(var, id) is not null
coalesce
returns the first non-null value in a list of fields. When neither condition is met a NULL
row will be returned and the where
clause will filter those out.
Upvotes: 1
Reputation: 246033
Filter with a WHERE
condition:
select id from "user"
where coalesce(var, '') = '';
Upvotes: 1