SQL queries a table for data that does not exist in another table-go to

Source: Internet
Author: User
#方法一: Use not in, easy to understand, low efficiency ~ Execution Time: 1.395 seconds ~
Select COUNT (1) from Ecs_goods WHERE ecs_goods.goods_id not in (SELECT ecs_member_price.goods_id from Ecs_member_price);
#方法二: Use left Join...on ..., "b.id isnull" indicates a record of NULL in the b.ID field after the connection is connected-execution time: 0.739 seconds ~
SELECT COUNT (1) from ecs_goods left JOIN ecs_member_price on ecs_goods.goods_id=ecs_member_price.goods_id WHERE Ecs_ MEMBER_PRICE.GOODS_ID is NULL;
#方法三: Logic is relatively complex, but fastest ~ execution time: 0.570 seconds ~
Select COUNT (1) from Ecs_goods C where (SELECT COUNT (1) as Num from Ecs_member_price WHERE Ecs_member_price.goods_id=ecs_ GOODS.GOODS_ID) = 0;

SQL queries a table for data that does not exist in another table-go to

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.