假设当前有三个表:
用户表(User)
订购表(Order)
产品表(Product)
内连接
1.自然连接和等值连接
--自然连接
select [User].UserId,OrderId
from [User]
inner join [Order] on [User].UserId = [Order].UserId
--等值连接
select U.UserId,O.OrderId
from [User] as U,[Order] as O
where U.UserId = O.UserId
2.不等连接
select [User].UserId,OrderId
from [User]
inner join [Order] on [User].UserId <> [Order].UserId
外连接
1.左外连接
select * from [User] as U
left join [Order] as O on U.UserId = O.UserId
2.右外连接
select * from [User] as U
right join [Order] as O on U.UserId = O.UserId
3.全连接
select * from [User] as U
full join [Order] as O on U.UserId = O.UserId
交叉连接
select * from [User] as U
cross join [Order] as O
where U.UserId = O.UserId