1 common table connections (inner join,left join,right join,full Join,cross join)if object_id(N'table1'N'U') is not NULL Drop Tabletable1if object_id(N'table2'N'U') is not NULL Drop Tabletable2Create TableTable1 (IDint, namevarchar( -))Insert intotable1Select 1,'Xia
-2", subject = subjects [0]}, new book {Title = "C # on Rails", publisher = Publishers [1], authors = new [] {authors [2]}, pagecount = 256, price = 35.5 M, publicationdate = new datetime (2007, 4, 1 ), ISBN = "0-222-77777-2", subject = subjects [0]}, new book {Title = "all your base are belong to us ", publisher = Publishers [1], authors = new [] {authors [3]}, pagecount = 1205, price = 35.5 M, publicationdate = new datetime (2006, 5, 5 ), ISBN = "0-333-77777-2", subject = subjects [2]}, new bo
Label:Prerequisites: Suppose there are two tables, one is the student table and the other is the Student score table. The table data are: One, internal connection-inner jion: The most common connection query may be that of identifying the student's name and score: Select S.name,m.mark from student S,mark m where S.id=m.studentid The above is our most common inner join, that is, within the connection, the student.id=mark.studentid conditions of the
1. Inner join(Typical join operations use comparison operators such as = or The inner join uses the comparison operator to match rows in two tables based on the values of the columns in each table. For example, retrieve all rows with the same student ID in the students and courses tables.2. Outer Join.Outer Join can be
Internal ConnectionINNER Join (equivalent connection):Only rows that are equal to the junction fields in two tables are displayed. This is the same effect as using Select to query multiple tables, so it is seldom used;External connection:Left JOIN: Displays all records in the left table on a left table basis, regardless of whether they match the association criteria, and the data in the right table shows on
I. Concepts
1. Cross join)Without the WHERE clause, it returns the Cartesian product of the two joined tables, and the number of rows returned is equal to the product of the number of rows in the two tables.For example:A: select a. *, B. * From Table1 A, Table2 B where a. ID = B. IDB: Select * From Table1 a cross join Table2 B where a. ID = B. IDIt is generally not recommended to use methods A and B, becaus
In-depth understanding of four SQL connections-left outer join, right outer join, inner join, and full link bitsCN.com
1. INNER JOIN(Typical join operations use comparison operators such as = or The inner join uses the comparison
1. Inner join(Typical join operations use comparison operators such as = or The inner join uses the comparison operator to match rows in two tables based on the values of the columns in each table. For example, retrieve all rows with the same student ID in the students and courses tables.2. Outer Join. Outer
? The connection conditions can be specified in the from or where clause. We recommend that you specify the connection conditions in the from clause. The where and having clauses can also contain search conditions to further filter the rows selected by the connection conditions.
Connections can be divided into the following types:
Internal Connection.(Typical join operations use comparison operators such as = or Equal connection and natural connectio
Table A records the following:
Aid anum
1 a20050111
2 a20050112
3 a20050113
4 a20050114
5 a20050115
Table B records the following:
Bid bname
1 2006032401
2 2006032402
3 2006032403
4 2006032404
8 2006032408
The experiment is as follows:
1. Left join
The SQL statement is as follows:
Select * from
Left join B
On a. Aid = B. Bid
The result is as follows:
Aid anum bid bname
1 a20050111 1 2006032401
2 a20050112
Test table:EMP Table Sal TableLeft JOIN: Results All rows are displayed in the table, and the right table determines that the column is the same as the left.SELECT * FROM EMP left join SAL on EMP. ename = SAL. ename; Right join: Results All rows are displayed in the table on the left, the table on the right is consistent with the tableSelect * from EMP right
The connection conditions can be specified in the FROM or WHERE clause. We recommend that you specify the connection conditions in the FROM clause. The WHERE and HAVING clauses can also contain search conditions to further filter the rows selected by the connection conditions.Connections can be divided into the following types:Internal Connection.(Typical join operations use comparison operators such as = or Equal connection and natural connection.The
Reprinted from: http://www.cnblogs.com/still-windows7/archive/2012/10/22/2734613.htmlPrerequisites: Suppose there are two tables, one is the student table and the other is the Student score table.The table data are:One, internal connection-inner jion:The most common connection query may be that of identifying the student's name and score:Select S.name,m.mark from student S,mark m where S.id=m.studentidThe above is our most common inner join, that is,
SQL left Outer Join, right Outer Join, full join, internal joinThe connection conditions can be specified in the from or where clause. We recommend that you specify the connection conditions in the from clause. The where and having clauses can also contain search conditions to further filter the rows selected by the connection conditions.Connections can be divide
Label:Original: http://blog.csdn.net/shadowyelling/article/details/7684714Left Join: Returns all the information in the table on the right and the information related to the left table conditionRight Join: Returns all of the information in the table in the list and information about the right table condition in the left tableInner Join: Returns information common
The join syntax is as follows: select [field] from [Table Name 1] inner/left/right/full join [Table name 2] on [Table Name 1. field 1] [Table name 2. field 2] cross join: the product of the flute. without any constraints, the number of rows in a table is multiplied by the number of rows in another table. Left join: re
This connection is often used in early query statements, which is a small problem. Therefore, I checked the information and summarized it as follows:
External connections are easier to understand,A. It is generally used in some classification codes. For example, if you have an employee information table, the position information isCodeAnd the meaning of this Code is described in the position table.B. Classified information storage. For example, in the preceding employee information table, the
A. =
Eg.
Select a. a B. B from a, B where a. A = B. A and A. C = 'herengang ';
Under this condition, it only shows the data that a. A = B. A and A. C = "herengang ".
Although it there is data which. C is "herengang", but if we can't find such record which. A value equals to. A in Table B, then it will be cleared.
B. Left join
Select a. a, B.
From Table
Left join Table B
On a. A = B. A and A. C = "herengang"
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.