Specifying NULL columns when MySQL LEFT join returns specific values detailed _mysql

Source: Internet
Author: User

The COALESCE function can accept more than one argument and returns the first Non-null value of those arguments, or null if all the supplied arguments are null
The Ifnull function, like the COALESCE function, can only accept two parameters
The IF function accepts three parameters, which is similar to the ternary (?:) function, that is, the first argument is not null and is not 0 o'clock, the second argument is returned, or the third argument is returned

Copy Code code as follows:

SELECT A.*,coalesce (t.cous,0) as Count from Brand as a
Left JOIN (select Brandid as Bid,count (1) as cous to Shopbrand Group by Brandid) T on A.brandid=t.bid
Order by Count DESC LIMIT 0,20

The above syntax is to do a statistic, itself will return null, but empty words is not a good practice, so use coalesce to solve

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.