, regardless of whether the table on the left has matching data: Select S.name,m.mark from student s right join Mark M on S.id=m.studentid The above statement takes all the data from the Mark score table, regardless of whether there is a data match in the student table, as shown in: Iv. fully connected-full join: Remove the data from the left and right two tables
Cross Jointable2Select * fromTable1,table2--The following three statements have the same effectSelect * fromTable1 A,table2 bwhereb.ID=a.idSelect * fromTable1 A Cross JoinTable2 bwhereb.ID=a.idSelect * fromTable1 AInner JoinTable2 b onb.ID=a.ID2 Cross Apply,outer apply(Cross Apply,outer apply is new in SQL Server 2005)There is a cross join in SQL Server 2000
table2 on Table1.id=table2.id-------------Results-------------ID Name ID Score------------------------------1 Lee 1 902 Zhang 2 1004 Wang Null NULL------------------------------NOTE: All clauses that contain table1, return table2 corresponding fields according to specified criteria, non-conforming null display3. Right Join(1) A right outer join is a reverse
. au_lname, P. pub_nameFrom authors as a inner join publishers as POn a. City = P. CityAnd a. State = P. StateOrder by A. au_lname ASC, A. au_fname ASC
Tables or views in the from clause can be specified in any order through internal connections or complete external connections. However, when you connect to a specified table or view from the left or right, the order of
Left join returns records that include all records in the left table and join fields in the right table.Right join returns records that include all records in the right table and the joined fields in the left table.Inner join (equivalent join) returns only rows with equal
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 n
Label: INNER JOIN (equivalent join) returns only rows that have the same join field in two tables Left join returns records that include all the records in the left table and the equivalent of the junction fields in the right table Right
Label: Inner JOIN (equivalent connection) returns only rows that have the same join field in two tables Left join returns records containing all the records in the left table and the equivalent of the junction fields in the right table Right join returns records that contain
some elements are in a, not in B, and vice versa.
Set " A" set "B"
AA BB
-------- --------
Item 1 Item 3
Item 2 Item 4
Item 3 Item 5
Item 4 Item 6
Left OUTER JOINNow execute the following SQL statement (left connection, OUTER join):
SELECT * from A left OUTER
Connection property. If the value is mapped to I by a hash function, then the tuple of relation s must be in H (RI), and the tuple of the relationship s must be in H (SI). Therefore, the tuples in H (RI) need to be compared with the tuples in H (SI) and not necessarily with any other partitions of S. It is obvious that this algorithm is much less expensive than the above algorithm. as two tables are partitioned, the benefit is that you can use para
. City = P. CityAnd a. State = P. StateOrder by A. au_lname ASC, A. au_fname ASC Tables or views in the from clause can be specified in any order through internal join or complete external join. However, when you use left or right outer join to specify a table or view, the order of
Label:Transferred from: http://blog.csdn.net/jz20110918/article/details/41806611 Let's say we have two tables. Table A is the sheet on the left. Table B is the list on the right. Each of them has four records, of which two records name is the same, as follows: Let's look at the different joins
Table A
Id
Name
1
Pirate
2
In the relational database management system, the relationship between data does not have to be determined when a table is created, and all information about an object is often stored in a table. When retrieving data, you can use the join operation to query information about different entities in multiple tables. Connection operations bring great flexibility to users. They can add new data types at any time
Categories.CategoryID.You can also link multiple on clauses in a JOIN statement, using the following syntax:SELECT fieldsFrom table1 INNER JOIN table2On table1.field1 compopr table2.field1 andOn table1.field2 compopr table2.field2 OROn table1.field3 compopr table2.field3;You can also nest JOIN statements with the following syntax:SELECT fieldsFrom table1 INNER
Categories.CategoryID.You can also link multiple on clauses in a JOIN statement, using the following syntax:SELECT fieldsFrom table1 INNER JOIN table2On table1.field1 compopr table2.field1 andOn table1.field2 compopr table2.field2 OROn table1.field3 compopr table2.field3;You can also nest JOIN statements with the following syntax:SELECT fieldsFrom table1 INNER
Categories.CategoryID.You can also link multiple on clauses in a JOIN statement, using the following syntax:SELECT fieldsFrom table1 INNER JOIN table2On table1.field1 compopr table2.field1 andOn table1.field2 compopr table2.field2 OROn table1.field3 compopr table2.field3;You can also nest JOIN statements with the following syntax:SELECT fieldsFrom table1 INNER
(primary table) and the SAL (schedule) information related to EMP.
Right connect [SQL] view plain copy
Select * from EMP right join SAL on EMP. ename = SAL.ename;
Right connection, table Sal is the primary table, so the query results show all the information of the salt (the primary table) and the EMP (schedule) and the information that Sal wants to close.
Internal connection [
. Although Table variables do not support indexes, table variables support primary keys. Therefore, you can use primary keys to replace indexes .)
If the temporary result set does not need to be changed much, but serves as a temporary associated dataset to join various datasets ), then indexes and statistical data may be more suitable (of course, this temporary result set must be large enough so that the cost of indexes and statistical data can be c
information of the EMP (primary table) and the SAL (schedule) information related to EMP.
Right-connect the Select * from emp to ' join SAL on EMP '. ename = SAL.ename; Right connection, table Sal is the primary table, so the query results show all the information of the salt (the primary table) and the EMP (schedule) and the information that Sal wants to close.
Internal Connection
modern relational algebra operations, SQL also provides:? Subqueries-similar to connections, but more flexible; in external queries, the results of subqueries can be used in expressions, lists, or data sets.This chapter describes multiple types of connections, simple and related subqueries, and the types of joins, links, and other content.2 Use connection2.1 connection typeIn relational algebra,
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.