MySQL ifnull simple instructions for use

Source: Internet
Author: User

About MySQL ifnull functions

The MySQL IFNULL function is one of the MySQL control flow functions that accepts two parameters, and if not NULL , returns the first argument. Otherwise, the IFNULL function returns a second argument.

Two parameters can be literal values or expressions.

The IFNULL syntax of the function is described below:

IFNULL(expression_1,expression_2);

If expression_1 not NULL , the IFNULL function returns, expression_1 otherwise returns expression_2 the result.

IFNULLThe function returns a string or number based on the context used.

MySQL's ifnull function example

See the following IFNULL function example:

Example-1

SELECT IFNULL(1,0); -- returns 1

Example-2

SELECT IFNULL(‘‘,1); -- returns ‘‘

Example-3

SELECT IFNULL(NULL,‘IFNULL function‘); -- returns IFNULL function
Example -4
SELECT Ifnull (Sex,'as fromuser-- If the query to this sex is a null value, then the value is assigned to an empty string

How does the statement in the above example work?

    • IFNULL(1,0)Returned 1 because it is 1 not NULL .
    • IFNULL(‘‘,1)Returns ‘‘ because the ‘‘ string is not NULL .
    • IFNULL(NULL,‘IFNULL function‘)Returns a IFNULL function string because the first argument is NULL .

MySQL ifnull simple instructions for use

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.