MySQL IF( ) Function Last Updated : 06 Jun, 2024 Comments Improve Suggest changes Like Article Like Report The MySQL IF() function is a control flow function that returns different values based on the result of a condition. IF() Function in MySQLThe IF() function in MySQL returns a value if the condition is TRUE and another value if the condition is FALSE. The MySQL IF() function can return values that can be either numeric or strings, depending upon the context in which the function is used. The IF() function accepts one parameter, which is the condition to be evaluated. SyntaxMySQL IF() function syntax is: IF(condition, true_value, false_value) Parameters: condition - It is used to specify the condition to be evaluated.true_value - It is an optional parameter that is used to specify the value to be returned if the condition evaluates to be true.false_value - It is an optional parameter that is used to specify the value to be returned if the condition evaluates to be false.Supported Versions of MySQLMySQL IF function is supported by the following version of MySQL: MySQL 5.7MySQL 5.6MySQL 5.5MySQL 5.1MySQL 5.0MySQL 4.1MySQL 4.0MySQL 3.23MySQL IF( ) Function ExamplesLet'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 1Implementing IF() function on a numeric condition and returning a string value. SELECT IF(5<12, 'TRUE', 'FALSE'); Output: TRUE Example 2Implementing IF() function with SQL STRCMP function to compare two strings SELECT IF(STRCMP('geeksforgeeks', 'gfg')=0, 'TRUE', 'FALSE'); Output: FALSE Example 3Implementing IF() function on a numeric condition and returning a numeric value. SELECT IF(5<12, '1', '0'); Output: 1 Important Points About MySQL IF() FunctionThe IF() function returns a value if the condition is TRUE or a different value if the condition is FALSE.The IF() function can return values that can be either numeric or strings depending on the context in which the function is used.The IF() function is useful for implementing conditional logic directly within a query.The IF() function is different from the MySQL IF statement, which is used for executing a set of SQL statements based on a pre-defined condition. Comment More infoAdvertise with us Next Article MySQL IF( ) Function S Shubrodeep Banerjee Follow Improve Article Tags : SQL mysql SQLmysql Similar Reads LEFT() Function in MySQL The LEFT() function in MySQL is used to extract a specified number of characters from the left side of a given string. It uses its second argument to decide, how many characters it should return. Syntax: LEFT (str, len)Parameter: This function accepts two parameters as mentioned above and described 1 min read LN() Function in MySQL LN() function : It is the function in MySQL is used to calculate the natural logarithm of a specific number with base e . The number must be greater than 0, otherwise it will return NULL. Syntax : LN(X) Parameter : LN() function accepts one parameter as mentioned above in the syntax and described be 2 min read MySQL ISNULL( ) Function The MySQL ISNULL() function is used for checking whether an expression is NULL or not. This function returns 1 if the expression passed is NULL; otherwise, it returns 0. The ISNULL() function in MySQL accepts the expression as a parameter and returns an integer with a value of a value 0 or 1 dependi 2 min read MID() function in MySQL MID() : This function in MySQL is used to extract a substring from a given input string. If the starting position is a positive number, then the substring of the given length will be extracted from the starting index. If negative, then the substring of the given length will be extracted from the end 2 min read LOG() Function in MySQL LOG() function in MySQL is used to calculate the natural logarithm of a specific number. The number must be >0 Otherwise it will return NULL. Syntax : LOG(X) Parameter : This method accepts one parameter as mentioned above and described below : X : A number whose logarithm value we want to calcul 3 min read STD() function in MySQL With the help of STD() function we can calculate population Standard deviation of an expression in MySQL. But, if there are no matching rows in the given expression it returns Null. Syntax : STD(expr); Parameter : This method accepts only one parameter. expr : Input expression from which we want to 3 min read MOD() Function in MySQL The MOD() function in MySQL is used to find the remainder of one number divided by another. The MOD() function returns the remainder of dividend divided by divisor. if the divisor is zero, it returns NULL. Syntax: MOD(N, M) or N % M or N MOD M Parameter : MOD() function accepts two parameter as ment 4 min read ELT() Function in MySQL In this article, we are going to cover ELT function with examples. In ELT function, number field will state that how many strings will be there. ELT function in MySQL is used to returns the string which is at index number specified in the argument list. In this function there is number field and str 1 min read ORD() Function in MySQL ORD() function in MySQL is used to find the code of the leftmost character in a string . If the leftmost character is not a multibyte character, it returns ASCII value. And if the leftmost character of the string str is a multibyte character, ORD returns the code for that character, calculated from 3 min read Like