IFNULL method is one of decision making method of mysql. It is used to avoid repeating of statement while using IF. When checking output value has null then send empty otherwise output value.
Syntax:
IFNULL(exp1,exp2);
If exp1 is not null returns exp1 value otherwise exp2.
|
How it works
Disadvantage:
Using IF() method
IF (group_concat(role_id) IS NOT NULL,group_concat(role_id),"")
When using IF() with NULL value check group_concat() method is executing two times.
Advantage:
Using IFNULL() method
IFNULL(group_concat(role_id),"")
When using IFNULL automatically return group_concat() output when it is not null otherwise returns empty string. So group_concat method is executing one time only when using IFNULL.
|
SELECT IFNULL(group_concat(role_id),"") as role_id_list FROM user_info WHERE user_id = 10;
|