MySQL ISNULL Function

Example

Test whether an expression is NULL:

SELECT ISNULL(NULL);

Definition and Usage

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.

Syntax

ISNULL(expression)

Continue reading MySQL ISNULL Function

MySQL IFNULL Function

Example

Return the specified value IF the expression is NULL, otherwise return the expression:

SELECT IFNULL(NULL, "Iampsp.com");

Definition and Usage

The IFNULL() function returns a specified value if the expression is NULL.

If the expression is NOT NULL, this function returns the expression.

Syntax

IFNULL(expression, alt_value)

Continue reading MySQL IFNULL Function

MySQL IF Function

Example

Return “YES” if the condition is TRUE, or “NO” if the condition is FALSE:

SELECT IF(500<1000, "YES", "NO");

Definition and Usage

The IF() function returns a value if a condition is TRUE, or another value if a condition is FALSE.

Syntax

IF(condition, value_if_true, value_if_false)

Continue reading MySQL IF Function

MySQL DATABASE Function

Example

Return the name of the current (default) database:

SELECT DATABASE();

Definition and Usage

The DATABASE() function returns the name of the current database.

If there is no current database, this function returns NULL or “”.

Syntax

DATABASE()

Continue reading MySQL DATABASE Function

MySQL CURRENT_USER Function

Example

Return the user name and host name for the MySQL account:

SELECT CURRENT_USER();

Definition and Usage

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.

 

Syntax

CURRENT_USER()

Continue reading MySQL CURRENT_USER Function

MySQL CONVERT Function

Example

Convert a value to a DATE datatype:

SELECT CONVERT("2017-08-29", DATE);

Definition and Usage

The CONVERT() function converts a value into the specified datatype or character set.

 

Syntax

CONVERT(value, type)

OR:

CONVERT(value USING charset)

Continue reading MySQL CONVERT Function

MySQL CONV Function

Example

Convert a number from numeric base system 10 to numeric base system 2:

SELECT CONV(15, 10, 2);

Definition and Usage

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.

 

Syntax

CONV(number, from_base, to_base)

Continue reading MySQL CONV Function

MySQL CONNECTION_ID Function

Example

Return the unique connection ID for the current connection:

SELECT CONNECTION_ID();

Definition and Usage

The CONNECTION_ID() function returns the unique connection ID for the current connection.

Syntax

CONNECTION_ID()

Continue reading MySQL CONNECTION_ID Function

MySQL COALESCE Function

Example

Return the first non-null value in a list:

SELECT COALESCE(NULL, NULL, NULL, 'W3Schools.com', NULL, 'Example.com');

Definition and Usage

The COALESCE() function returns the first non-null value in a list.

Syntax

COALESCE(val1, val2, ...., val_n)

Continue reading MySQL COALESCE Function

MySQL CAST Function

Example

Convert a value to a DATE datatype:

SELECT CAST("2017-08-29" AS DATE);

Definition and Usage

The CAST() function converts a value (of any type) into the specified datatype.

 

Syntax

CAST(value AS datatype)

Continue reading MySQL CAST Function