I’m trying to understand what this SQL (from a MySQL installation) actually does:
IF(coalesce(a.entity_id, 0) != 0, 0, 1)
While I understand what the coalesce does I don’t understand how the IF statement is modifying it.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think:
coalesce(a.entity_id, 0) – return the first not null value,
if a.entity_id is not null you get 0 as a result of if, else 1.
a.entity_id = null => coalesce = 0 => if = 1
a.entity_id is not null => coalesce = a.entity_id => if = 0