Label:--Build Table Table1,table2:CREATE TABLE table1 (ID int,name varchar (10))CREATE TABLE table2 (ID int,score int)Insert INTO table1 Select 1,leeInsert INTO table1 Select 2,zhangInsert INTO table1 Select 4,wangInsert INTO table2 Select 1,90Insert INTO table2 Select 2,100Insert INTO table2 select 3,70such as table-------------------------------------------------Table1 | table2 |-------------------------------------------------ID Name |id Score |1 Lee | 90 |2 Zhang 100 |4 Wang |3 70 |---------
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
Inner join
There are two tables A and B.
The structure of Table A is as follows:
Aid: int; identifies the seed, primary key, and auto-increment ID
Aname: varchar
The data, that is, the records from select * From A, are shown in 1:
Figure 1: data in Table
Table B has the following structure:
Bid: int; identifies the seed, primary key, and auto-increment ID
Bnameid: int
Data, that is, the records from select * from B, are sh
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
, c.cat_name from Mingoods G, category C WHERE G. cat_id = c.cat_id; 2. Left join query ... on ... syntax : select a.filed, [A.filed2, .....,] b.filed, [b.filed4 ...,] from join L T;right table> as B on Suppose there is a, b two tables, the left connection query is a table on the left, B table on the right, A and B table through a relationship to correlate rows, B to match a table. 2.1 Take a loo
Let's start by looking at the results of the left join and the right join and the Inner join and the full join working on the table.
Create a new two table in the database and insert the data you want to test.
New table:[SQL]View PlainCopyUse [Test]GO/****** object: Table [dbo].[ EMP] Script Date: 06/22/2
Tags: http strong ar Data div sp on ad efLet's start by looking at the results of the left join and the right join and the Inner join and the full join working on the table.
Create a new two table in the database and insert the data you want to test.
New table:[SQL]Use [Test]
GO
/****** object: Table
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
Monkey
3
Ninja
4
Spaghetti
Differences between inner join, left JOIN, right join, outer join in SQLFor example, you'll know!Table A (A1,B1,C1) b (A2,B2)A1 B1 C1 A2 B201 Mathematics 95 01 Sheets Three02 Language 90 02 John Doe English Harry Select A.*, b.* from AINNER JOIN B on (A.A1=B.A2)The result is
Take a look at the results of the left join and the right join with the Inner join and the full join to manipulate the table.
Create a new two table in the database and insert the data you want to test.
New table:[SQL]View PlainCopy
Use [Test]
GO
/****** object: Table [dbo].[ EMP] Script Date: 06/
? 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
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,
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"
[Test @ ora1] SQL> select * From A; No. Name ---- ---------- 1000 Zhang San 2000 Li Si 3000 Wang Wu [test @ ora1] SQL> select * from B; product NO. ---- ---------- 1000 TV set 2000 video recorder 4000 bicycle [test @ ora1] SQL> set null Null Value -- Here I define null as [null value] [test @ ora1] SQL> select. *, B. * From a inner join B on. no. = B. no.; No. name No. Product ---- ---------- 1000 Zhang San 1000 TV set 2000 Li Si 2000 video recorder [
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.