When you make a table association, add conditions after each query and add conditions after all associations which are fast

Source: Internet
Author: User
Example 1:select * from Contact_card as C
INNER JOIN Contact_card_extend as B on c.uuid = B.uuid and c.uuid= ' ax61t09bpcmmhsxisvbav1mdb71jzwt3 ' and c.status= ' active '
INNER JOIN Contact_card_vcardinfo as info on c.uuid=info.card_id;

Example 2:select * from Contact_card as C
INNER JOIN Contact_card_extend as B on c.uuid = B.uuid
INNER JOIN Contact_card_vcardinfo as info on c.uuid=info.card_id
WHERE c.uuid= ' ax61t09bpcmmhsxisvbav1mdb71jzwt3 ' and c.status= ' active '


Reply to discussion (solution)

Like both
However, the latter is generally written because c.uuid= ' ax61t09bpcmmhsxisvbav1mdb71jzwt3 ' and c.status= ' active ' are not connected to the connection

Like both
However, the latter is generally written because c.uuid= ' ax61t09bpcmmhsxisvbav1mdb71jzwt3 ' and c.status= ' active ' are not connected to the connection


That's it, son.

In terms of big data, it is not known whether the former is faster, in theory, the former is the first query through the results of the association, and the first query has been conditional filtering, it should be more than the second all the query after the association after the conditional filtering faster. I think it should have been so without a try so just ask.

That's just your imagination.
There is a process in the database that is specifically used to parse the join command, and it is parsed for the connection-independent expression to be placed in the WHERE clause

If you only want the primary table to qualify for a record to participate in the query, you should use a subquery
SELECT * FROM
(SELECT * from Contact_card where uuid= ' ax61t09bpcmmhsxisvbav1mdb71jzwt3 ' and status= ' active ') As C
INNER JOIN Contact_card_extend as B on c.uuid = B.uuid
INNER JOIN Contact_card_vcardinfo as info on c.uuid=info.card_id

Educated, thank you, big God son! Have corrected the mistake!

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