In the following SQL select statement, I want nationality to print if name is null, and I have a SQL clause’s if syntax working, but am not seeing nationality print out in the following:
table test2
id integer
case integer
nationality char(10)
name char(24)
1 1 france ""
2 2 england john
select t.id,
if(t.name is null, t.nationality, t.name)
as name_equivalent
from test2 t;
produces
id name_equivalent
1 ""
2 john
Why is that?
Thank You.
nullis not equivalent to the empty string. The empty string''is a valid form of data,nullindicates there is no data present.Try either
Or set the name in the first column to null