test | sid | sname | scd | stime | test1 | sid | uid | ||||
1 | tt | 2 | 9.3 | 1 | 2 | ||||||
2 | uu | 1 | 9.11 | 3 | 4 | ||||||
3 | oo | 2 | 9.12 | 5 | 6 | ||||||
4 | pp | 2 | 11.11 | 7 | 8 | ||||||
5 | ll | 3 | 12.12 | 9 | 10 | ||||||
6 | kk | 4 | 12.13 | 11 | 12 | ||||||
7 | jjj | 1 | 13.14 | 13 | 14 | ||||||
8 | mm | 1 | 10.11 | 15 | 16 | ||||||
select * from test join test1 on test.sid=test1.sid; | 内连接 | ||||||||||
sid | sname | scd | stime | sid | uid | 内连接为取出他们的交集 | |||||
1 | tt | 2 | 9.3 | 1 | 2 | ||||||
3 | oo | 2 | 9.12 | 3 | 4 | ||||||
5 | ll | 3 | 12.12 | 5 | 6 | ||||||
7 | jjj | 1 | 13.14 | 7 | 8 | ||||||
select * from test left join test1 on test.sid=test1.sid; | |||||||||||
sid | sname | scd | stime | sid | uid | 左连接是以左表作为主表,找出对应的右表内容 | |||||
1 | tt | 2 | 9.3 | 1 | 2 | ||||||
2 | uu | 1 | 9.11 | null | null | ||||||
3 | oo | 2 | 9.12 | 3 | 4 | ||||||
4 | pp | 2 | 11.11 | null | null | ||||||
5 | ll | 3 | 12.12 | 5 | 6 | ||||||
6 | kk | 4 | 12.13 | null | null | ||||||
7 | jjj | 1 | 13.14 | 7 | 8 | ||||||
8 | mm | 1 | 10.11 | null | null | ||||||
select * from test right join test1 on test.sid=test1.sid; | |||||||||||
sid | sname | scd | stime | sid | uid | 右连接是以左表作为主表,找出对应的左表内容 | |||||
1 | tt | 2 | 9.3 | 1 | 2 | ||||||
3 | oo | 2 | 9.12 | 3 | 4 | ||||||
5 | ll | 3 | 12.12 | 5 | 6 | ||||||
7 | jjj | 1 | 13.14 | 7 | 8 | ||||||
null | null | null | null | 9 | 10 | ||||||
null | null | null | null | 11 | 12 | ||||||
null | null | null | null | 13 | 14 | ||||||
null | null | null | null | 15 | 16 |