The Union intersection join (INNER JOIN, outer join) of SQL statement is introduced _mssql

Source: Internet
Author: User
Tags joins
1. A. Union select Column1, column2 from table1 Union select Column1, column2 from Table2 B. Intersection join SELECT * FROM table 1 as a JOIN table2 B on A.name=b.name c. No in SELECT * "from table1 WHERE name does not" (SELECT name from table2) d. Cartesian product The SELECT * FROM table1 CROSS JOIN table2 is the same as the select * from Table1,table2 2. The difference between union and all in SQL is that the former will remove duplicate entries and the latter will remain. A. Union SQL STATEMENT1 Union SQL Statement2 b. Union ALL SQL Statement1 UNION ALL SQL Statement2 3. The connections in various join SQL in SQL can be divided into inner joins, outer joins, and Cross joins (that is, Cartesian product) a. Cross-join Cross join if you do not take a WHERE condition clause, it returns the Cartesian product of the two tables that are connected, and the number of rows that return the result equals the product of two table rows; For example, the SELECT * from table1 CROSS JOIN table2 is equivalent to the SELECT * from Table1,table2 is generally not recommended, because if there is a WHERE clause, the data table of the row that will often be the product of two table rows is then Select from from where condition. Therefore, if two of the required social tables are too large, they will be very, very slow and not recommended for use. B. Inner JOIN INNER Join if you only use the SELECT * from table1 INNER join table2 do not specify a join condition, the same as the result of a cross join. In general, however, you need to specify a join condition using the INNER join. --the equivalent connection (= number applies to join condition, does not remove duplicate column) SELECT * FROM table1 as a INNER join table2 as B on a.column=b.column--Unequal connection (>,>=,< , <=,!>!<,<>) such as SELECT * from table1 as a INNER join table2 as B on a.column<>b.column--natural join (will remove duplicate columns) C. Outer join out ER JOIN First the difference between the inner and outer joins: The inner join, if not specified, is the same as that of the Cartesian product, but unlike the Cartesian product, where there is no Cartesian product, the data table with the product of the number of lines is more efficient than the Cartesian product cross connection. Specify the inner join of the condition, returning only entries that meet the join condition. The outer joins are different, and the results returned include not only the rows that meet the join criteria, but all rows of data on the left table (when the left outer join), the right table (when the right is connected), or on both sides of the connection (all outside). 1 left [OUTER] join shows rows of data that match the criteria, and shows rows of data on the left table that do not match the criteria, and no corresponding entry on the right shows null such as SELECT * from table1 as a left [OUTER] join on a. Column=b.column 2) Right outer connection rights [OUTER] join displays data rows that match the criteria, and shows rows of data on the right table that do not match the criteria, and no corresponding entries on the left display null such as SELECT * from table1 as a right [OUTER] JOIN on A.column=b.column 3 The full outer join displays the data rows that match the criteria, displaying the left and right rows of data that are not eligible, and showing null on both sides of the corresponding

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.