左连接,右连接,全连接,内连接,交叉连接,自连接

来源:互联网 发布:淘宝限时促销要钱 编辑:程序博客网 时间:2024/05/17 17:38

---右连接,以右边表为准,左表的记录只有当左表ID右表中存在才显示
select * from table1 t
right join table2 tt
on t.id=tt.id
---左连接,以左边表为准,右表的记录只有当右表ID左表中存在才显示
select * from table1 t
left join table2 tt
on t.id=tt.id
---两表全显示
select * from table1 t
full join table2 tt
on t.id=tt.id
---内连接,同时存在于两个表
select * from table1 t
inner join table2 tt
on t.id=tt.id
---交叉连接,不带条件时,是两个表乘积
select * from table1 t
cross join table2 tt
on t.id=tt.id
---自连接
select department'部门',
(select department from table1 t where t.id=tt.id)'上级部门'
where t as tt

原创粉丝点击