SQL Server's join query notation

Source: Internet
Author: User

1. Internal connectionsyntax: "Join, INNER join"function: Two tables connected, plus on match two tables common conditions. Example 1:SELECT tb_o_i.* from tb_o_i INNER JOINTb_o_ig on tb_o_i.c_id=Tb_o_ig.c_id and tb_o_i.C_provider=' 00996 'Example 2:SELECT tb_o_i.* from tb_o_i Join Tb_o_ig on tb_o_i.c_id=Tb_o_ig.c_id WHERE tb_o_i.C_provider=' 00996 '2. Left connectionsyntax: "LEFT JOIN, left OUTER join"function: Refers to the first to take out all the data on the left table, and then add on to the two table Common Criteria matching data. Example 3:SELECT tb_o_i.* from tb_o_i Left JOIN Tb_o_ig on tb_o_i.c_id=Tb_o_ig.c_id WHEREtb_o_i.C_provider=' 00996 'Note: On can only be followed by an association condition, the subsequent conditions are added to where, the following is an error, because the second condition on has no effect.Example 4:SELECT tb_o_i.* from tb_o_i Left JOIN Tb_o_ig on tb_o_i.c_id=Tb_o_ig.c_id and tb_o_i.C_provider=' 00996 '3. Right connectionsyntax: "Right join, right OUTER join"function: Refers to the first to remove all the data from the right table, and then add on to the two table with the common criteria to match the data. Example 5:SELECT tb_o_i.* from tb_o_i Right JOIN Tb_o_ig on tb_o_i.c_id=Tb_o_ig.c_id WHEREtb_o_i.C_provider=' 00996 ' 4. Fully Connectedsyntax: "full join, full OUTER join"effect: A full outer join returns all rows from the left and right tables. When a row does not have a matching row in another table, the selection list column of the other table contains null values, and if there are matching rows between the tables, the entire result set row contains the data values of the base table. Note: The syntax of Outer can be omitted, for example you can use a LEFT join or right join, in essence, Outer Join is inclusive, let it be inclusive!Unlike the exclusivity of the Inner join, the results of the query in the left Outer join will contain all the data from the left table, and the query for right Outer join will contain all of the data from the left table, in reverse.

SQL Server's join query notation

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.