Software >> Services >> RDBMS >> MySQL >> What are some example usage of the IF function

following example will set newordering to the value of '1' if the result of earlier query makes @catcount NULL, otherwise it will be set as @catcount+1

SET @catcount = (SELECT MAX(ordering) FROM `jos_sobi2_cat_items_relations` WHERE `catid` = '39');
SET @newordering = (SELECT IF(@catcount,@catcount+1,1));