MySQL IF( ) Function Examples
Let’s us look at some examples of the IF function in MySQL. Learning MySQL IF() function with examples, helps in understanding the concepts better.
Example 1
Implementing IF() function on a numeric condition and returning a string value.
SELECT IF(5<12, 'TRUE', 'FALSE');
Output:
TRUE
Example 2
Implementing IF() function with SQL STRCMP function to compare two strings
SELECT IF(STRCMP('w3wiki', 'gfg')=0, 'TRUE', 'FALSE');
Output:
FALSE
Example 3
Implementing IF() function on a numeric condition and returning a numeric value.
SELECT IF(5<12, '1', '0');
Output:
1
MySQL IF( ) Function
The MySQL IF() function is a control flow function that returns different values based on the result of a condition.
Contact Us