I have following query to handle null value and flag those based on two table join
however c.pure_proc_flag is null then 0 else 1 does not provide the result I expect.
query as following
select
b.procedure_Type as procedure_type,b.procedure_Episode_ID as episode_id,b.claim_claim_number as claim_number,1.0 as card_procedure_ind,
c.pure_proc_flag as pure_proc_flag_orig,
ifnull(c.pure_proc_flag,0) as pure_proc_flag2,
case when c.pure_proc_flag is null then 0 else 1 end as pure_proc_flag3
from
(select procedure_Type,procedure_Episode_ID,claim_Claim_Number FROM HEALTHPLAN_SANDBOX.JX_INS_CLAIMS_PROCEDURE
where procedure_Type='Cardiology - CABG' and procedure_Episode_ID='1029877775') b
left join
(select procedure_Type,procedure_Episode_ID,claim_Claim_Number,1 as pure_proc_flag FROM HEALTHPLAN_SANDBOX.JX_INS_CLAIMS_PROCEDURE_SOURCE
where procedure_Type='Cardiology - CABG' and procedure_Episode_ID='1029877775') c
on b.procedure_Type=c.procedure_Type and b.procedure_Episode_ID=c.procedure_Episode_ID and b.claim_Claim_Number=c.claim_Claim_Number
the query is pretty straightforward.
I use b table left join c table
whereever the raw in b table not find the match in c table, It return null value, rest should be 1 show as pure_proc_flag_orig column
based on the condition of pure_proc_flag in c table, I want to flag those into 0 or 1
For understanding. pure_proc_flag2 and pure_proc_flag3 logic are the same.
however the result is different.

as you can see ifnull(c.pure_proc_flag,0) as pure_proc_flag2 work as expect, however, case when c.pure_proc_flag is null then 0 else 1 end as pure_proc_flag3 does not work. (it indicated no blank row in c table. however, as we can see in pure_proc_flag_orig column, c table have blank row due to left join.
do I miss any important concept in mysql?
system version:
aurora_version 2.02.5
innodb_version 5.7.12
EXPLAIN SELECT ...1 as pure_proc_flagin c . This means that you will never get 0 or null in any case. Then why you have this statementcase when c.pure_proc_flag is null then 0 else 1 end as pure_proc_flag3, This will always be` 1`.