IF Condition in MySQL

A condition is verified using the MySQL IF() function. If the condition is TRUE, the IF() function returns a value, and if the condition is FALSE, it returns a different value. Keep in mind that an IF statement differs from an IF function.

The IF function can return a string or a numeric value depending on how it is utilized.

SELECT IF(100 < 200, 1, 0);
Result: 1
SELECT IF(‘hello’ = ‘Hello’, ‘TRUE’, ‘FALSE’);
Result: TRUE
SELECT IF(‘hello’ = ‘Hello’, “YES”, “NO”);
Result: YES
SELECT IF(STRCMP(“hello”,”Hell”) = 0, “YES”, “NO”);
Result: NO

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s