Transforming a subquery into a join connection query

Source: Internet
Author: User
Tags joins
Original Sub-query

SELECT COUNT (*) as Tp_count from Sdb_b2c_orders WHERE pay_status= ' 1 ' and createtime>1413533130 and Area_code in (1030,1 031,1032,1033) and member_id in (select member_id from Sdb_invite_invite where in_member_id=14273 or in_member_id=13742 or in_member_id=14299) LIMIT 1

Execution results are22

Use a connection query instead of the subquery above

SELECT COUNT (*) as Tp_count from Sdb_b2c_orders as Bo INNER joins Sdb_invite_invite as II on bo.member_id=ii.in_member_id W Here bo.pay_status= ' 1 ' and Bo.area_code in (1030,1031,1032,1033) and bo.createtime>1413533130 and ii.in_member_id in ( 14273,13742,14299)

The result of execution is131

Reply content:

Original Sub-query

SELECT COUNT (*) as Tp_count from Sdb_b2c_orders WHERE pay_status= ' 1 ' and createtime>1413533130 and Area_code in (1030,1 031,1032,1033) and member_id in (select member_id from Sdb_invite_invite where in_member_id=14273 or in_member_id=13742 or in_member_id=14299) LIMIT 1

Execution results are22

Use a connection query instead of the subquery above

SELECT COUNT (*) as Tp_count from Sdb_b2c_orders as Bo INNER joins Sdb_invite_invite as II on bo.member_id=ii.in_member_id W Here bo.pay_status= ' 1 ' and Bo.area_code in (1030,1031,1032,1033) and bo.createtime>1413533130 and ii.in_member_id in ( 14273,13742,14299)

The result of execution is131

SDB_INVITE_INVITE.IN_MEMBER_ID Records have duplicates

  • 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.