|
@@ -19,9 +19,9 @@ insert into table2 select 3, 70
|
|
|
|
|
|
```
|
|
```
|
|
table1 | table2
|
|
table1 | table2
|
|
-------------------------------------------------------
|
|
|
|
|
|
+-----------------------------------------------------------------------------------------
|
|
id name | id score
|
|
id name | id score
|
|
- 1 lee | 1 90
|
|
|
|
|
|
+ 1 lee | 1 90
|
|
2 zhang | 2 100
|
|
2 zhang | 2 100
|
|
4 wang | 3 70
|
|
4 wang | 3 70
|
|
```
|
|
```
|
|
@@ -44,8 +44,8 @@ select * from table1 inner join table2 on table1.id = table2.id
|
|
|
|
|
|
```
|
|
```
|
|
id name id score
|
|
id name id score
|
|
-----------------------------------------
|
|
|
|
- 1 lee 1 90
|
|
|
|
|
|
+-----------------------------------------------------------------------------------------
|
|
|
|
+ 1 lee 1 90
|
|
2 zhang 2 100
|
|
2 zhang 2 100
|
|
```
|
|
```
|
|
|
|
|
|
@@ -80,8 +80,8 @@ select * from table1 left join table2 on table1.id = table2.id
|
|
|
|
|
|
```
|
|
```
|
|
id name id score
|
|
id name id score
|
|
-------------------------------------------
|
|
|
|
- 1 lee 1 90
|
|
|
|
|
|
+-----------------------------------------------------------------------------------------
|
|
|
|
+ 1 lee 1 90
|
|
2 zhang 2 100
|
|
2 zhang 2 100
|
|
4 wang NULL NULL
|
|
4 wang NULL NULL
|
|
```
|
|
```
|
|
@@ -102,10 +102,10 @@ select * from table1 right join table2 on table1.id = table2.id
|
|
|
|
|
|
```
|
|
```
|
|
id name id score
|
|
id name id score
|
|
-------------------------------------------
|
|
|
|
- 1 lee 1 90
|
|
|
|
|
|
+-----------------------------------------------------------------------------------------
|
|
|
|
+ 1 lee 1 90
|
|
2 zhang 2 100
|
|
2 zhang 2 100
|
|
- NULL NULL 3 70
|
|
|
|
|
|
+ NULL NULL 3 70
|
|
```
|
|
```
|
|
|
|
|
|
[^注释]: 包含 table2 的所有子句,根据指定条件返回 table1 相应的字段,不符合的以 null 显示
|
|
[^注释]: 包含 table2 的所有子句,根据指定条件返回 table1 相应的字段,不符合的以 null 显示
|
|
@@ -124,11 +124,11 @@ select * from table1 full join table2 on table1.id = table2.id
|
|
|
|
|
|
```
|
|
```
|
|
id name id score
|
|
id name id score
|
|
-------------------------------------------
|
|
|
|
- 1 lee 1 90
|
|
|
|
|
|
+-----------------------------------------------------------------------------------------
|
|
|
|
+ 1 lee 1 90
|
|
2 zhang 2 100
|
|
2 zhang 2 100
|
|
4 wang NULL NULL
|
|
4 wang NULL NULL
|
|
- NULL NULL 3 70
|
|
|
|
|
|
+ NULL NULL 3 70
|
|
```
|
|
```
|
|
|
|
|
|
[^注释]: 返回左右连接的和(见上左、右连接)
|
|
[^注释]: 返回左右连接的和(见上左、右连接)
|
|
@@ -149,14 +149,14 @@ select * from table1 cross join table2
|
|
|
|
|
|
```
|
|
```
|
|
id name id score
|
|
id name id score
|
|
-------------------------------------------
|
|
|
|
- 1 lee 1 90
|
|
|
|
|
|
+-----------------------------------------------------------------------------------------
|
|
|
|
+ 1 lee 1 90
|
|
2 zhang 1 90
|
|
2 zhang 1 90
|
|
4 wang 1 90
|
|
4 wang 1 90
|
|
- 1 lee 2 100
|
|
|
|
|
|
+ 1 lee 2 100
|
|
2 zhang 2 100
|
|
2 zhang 2 100
|
|
4 wang 2 100
|
|
4 wang 2 100
|
|
- 1 lee 3 70
|
|
|
|
|
|
+ 1 lee 3 70
|
|
2 zhang 3 70
|
|
2 zhang 3 70
|
|
4 wang 3 70
|
|
4 wang 3 70
|
|
```
|
|
```
|
|
@@ -185,7 +185,7 @@ insert into table3 select 3, null
|
|
|
|
|
|
```
|
|
```
|
|
table3
|
|
table3
|
|
----------------------
|
|
|
|
|
|
+-----------------------------------------------------------------------------------------
|
|
id score
|
|
id score
|
|
1 null
|
|
1 null
|
|
2 null
|
|
2 null
|
|
@@ -202,7 +202,7 @@ update b set b.score = a.score from table2 a, table3 b where a.id = b.id
|
|
|
|
|
|
```
|
|
```
|
|
table3
|
|
table3
|
|
----------------------
|
|
|
|
|
|
+-----------------------------------------------------------------------------------------
|
|
id score
|
|
id score
|
|
1 90
|
|
1 90
|
|
2 100
|
|
2 100
|
|
@@ -221,9 +221,9 @@ delete from table1 where not exists(select 1 from table2 b where table1.id = b.i
|
|
|
|
|
|
```
|
|
```
|
|
table1 | table2
|
|
table1 | table2
|
|
-------------------------------------------------------
|
|
|
|
|
|
+-----------------------------------------------------------------------------------------
|
|
id name | id score
|
|
id name | id score
|
|
- 1 lee | 1 90
|
|
|
|
|
|
+ 1 lee | 1 90
|
|
2 zhang | 2 100
|
|
2 zhang | 2 100
|
|
4 wang | 3 70
|
|
4 wang | 3 70
|
|
```
|
|
```
|
|
@@ -232,11 +232,11 @@ delete from table1 where not exists(select 1 from table2 b where table1.id = b.i
|
|
|
|
|
|
```
|
|
```
|
|
table1 | table2
|
|
table1 | table2
|
|
-------------------------------------------------------
|
|
|
|
|
|
+-----------------------------------------------------------------------------------------
|
|
id name | id score
|
|
id name | id score
|
|
- 1 lee | 1 90
|
|
|
|
|
|
+ 1 lee | 1 90
|
|
2 zhang | 2 100
|
|
2 zhang | 2 100
|
|
- | 3 70
|
|
|
|
|
|
+ | 3 70
|
|
```
|
|
```
|
|
|
|
|
|
[^注释]: 将 table2 表中未使用的 table1 表编号删除
|
|
[^注释]: 将 table2 表中未使用的 table1 表编号删除
|
|
@@ -253,11 +253,11 @@ delete from table1 where exists(select 1 from table2 b where table1.id = b.id)
|
|
|
|
|
|
```
|
|
```
|
|
table1 | table2
|
|
table1 | table2
|
|
-------------------------------------------------------
|
|
|
|
|
|
+-----------------------------------------------------------------------------------------
|
|
id name | id score
|
|
id name | id score
|
|
4 wang | 1 90
|
|
4 wang | 1 90
|
|
- | 2 100
|
|
|
|
- | 3 70
|
|
|
|
|
|
+ | 2 100
|
|
|
|
+ | 3 70
|
|
```
|
|
```
|
|
|
|
|
|
[^注释]: 将 table2 表中使用的 table1 表编号删除
|
|
[^注释]: 将 table2 表中使用的 table1 表编号删除
|