My table is as below
ID | email | ref
-------+-----------------------------------+------------
12 | test@testmail.com | 0
12 | test@testmail.com | 1
Now the requirement of the query is to retrieve the ID and the email where the reference is 0, however, if the email is null with ref 0 then it should take the email value of ref 1. If both ref has the email value then by default it should take 0.
I tried with the below query but it fails, it is giving me both the value
select
id,
email,
ref
from
table1
where ref in (case when email is not null then 0 else 1 end) and ID=12;
Is there any way to achieve this?