The difference between on and where during connection query.

Source: Internet
Author: User

The difference between on and where during connection query.

The northwind data test is used.

1. Internal Connection. Inner is omitted during connection. Query the order of customer Vinet.

Select * from orders a join MERs B
On a. customerid = B. customerid and A. customerid = 'vinet'

The returned records are filtered by Vinet.

 

Select * from orders a join MERs B
On a. customerid = B. customerid
Where a. customerid = 'vinet'

Returns the same result as the preceding query.

That is to say, there is no difference between on and where in internal connection. Will filter the returned records.


2. External Connection, left connection. The same query condition.

Select * from orders a left join MERs B
On a. customerid = B. customerid and A. customerid = 'vinet'

If all the records in the left table are returned, they are not filtered by A. mermerid = 'vinet.

Select * from orders a left join MERs B
On a. customerid = B. customerid
Where a. customerid = 'vinet'

The returned records are filtered.

This is because the connection query generates a temporary table and then returns the temporary table to the user. The on condition is the condition statement used when a temporary table is generated. Records in the left table are returned no matter whether it is true or not.

The where condition is used after a temporary table is generated. At this time, it has nothing to do with the connection. It returns records that meet the conditions.

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.