Example
Compare two expressions:
SELECT NULLIF(25, 25);
Definition and Usage
The NULLIF() function compares two expressions and returns NULL if they are equal. Otherwise, the first expression is returned.
Syntax
NULLIF(expr1, expr2)
Compare two expressions:
SELECT NULLIF(25, 25);
The NULLIF() function compares two expressions and returns NULL if they are equal. Otherwise, the first expression is returned.
NULLIF(expr1, expr2)
Return the AUTO_INCREMENT id of the last row that has been inserted in a table:
SELECT LAST_INSERT_ID();
The LAST_INSERT_ID() function returns the AUTO_INCREMENT id of the last row that has been inserted in a table.
LAST_INSERT_ID(expression)
Test whether an expression is NULL:
SELECT ISNULL(NULL);
The ISNULL() function returns 1 or 0 depending on whether an expression is NULL.
If expression is NULL, this function returns 1. Otherwise, it returns 0.
ISNULL(expression)
Return the specified value IF the expression is NULL, otherwise return the expression:
SELECT IFNULL(NULL, "Iampsp.com");
The IFNULL() function returns a specified value if the expression is NULL.
If the expression is NOT NULL, this function returns the expression.
IFNULL(expression, alt_value)
Return “YES” if the condition is TRUE, or “NO” if the condition is FALSE:
SELECT IF(500<1000, "YES", "NO");
The IF() function returns a value if a condition is TRUE, or another value if a condition is FALSE.
IF(condition, value_if_true, value_if_false)
Return the name of the current (default) database:
SELECT DATABASE();
The DATABASE() function returns the name of the current database.
If there is no current database, this function returns NULL or “”.
DATABASE()
Return the user name and host name for the MySQL account:
SELECT CURRENT_USER();
The CURRENT_USER() function returns the user name and host name for the MySQL account that the server used to authenticate the current client.
The result is returned as a string in the UTF8 character set.
CURRENT_USER()
Convert a value to a DATE datatype:
SELECT CONVERT("2017-08-29", DATE);
The CONVERT() function converts a value into the specified datatype or character set.
CONVERT(value, type)
OR:
CONVERT(value USING charset)
Convert a number from numeric base system 10 to numeric base system 2:
SELECT CONV(15, 10, 2);
The CONV() function converts a number from one numeric base system to another, and returns the result as a string value.
Note: This function returns NULL if any of the parameters are NULL.
CONV(number, from_base, to_base)
Return the unique connection ID for the current connection:
SELECT CONNECTION_ID();
The CONNECTION_ID() function returns the unique connection ID for the current connection.
CONNECTION_ID()