The difference between using the left, right, full, and inner joins and using the Where condition statement

Source: Internet
Author: User
Tags joins
the difference between using the left, right, full, and inner joins and using the Where condition statementFrom learning the SQL statement to the present, never used the left and right connection, perhaps someone would be surprised, but it is not, because I have been using the WHERE condition statement. I also want to try the effect, I did a test today, and finally know where conditions can only be connected within the connection function, because it is impossible to not meet the conditions of the statement displayed, but in most instances of life is certainly there, like a person's number still exists, But this person's message has been deleted, this number has no real meaning. Database: SQL SERVER 2000 establishes arbitrary databases and establishes tables: CREATE TABLE t1 (ID int,name varchar (), teacher int) CREATE TABLE t2 (ID int,name varchar INSERT into T1 values (1, ' AA ', 1) inserts into the T1 values (2, ' BB ', 2) insert into T1 values (3, ' CC ', 2) inserts into T1 value S (4, ' AA ', 3) insert into T2 values (1, ' Mr. Zhang ') insert into T2 values (2, ' Miss Wang ') insert into T2 values (4, ' von Teacher ') 1, use the left and right connections, full connection, respectively. Results are as follows: Left JOIN: SELECT * from T1 LEFT join T2 on-T1.teacher=t2.id Right connection: SELECT * from t1 right-to-left join T2 on t1.teacher=t2.id inner connection: s Elect * T1 INNER join T2 on t1.teacher=t2.id select * from t1 join T2 on t1.teacher=t2.id (default is inner) Full connection: SELECT * Fro M T1 full join T2 on T1.teacher=t2.id 2, connect query using WHERE Condition: Select t1.*,t2.* from T1,t2 where t1.teacher=t2.id where cannot get left, right, full The effect of the connection.

This article originates from: Feng Libin's blog




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.