一:交叉连接-----笛卡尔集(积):
1. select A.name, B.age from A,B
2. select A.name, B.age from A cross join B
二:内连接
1. select A.name, B.age from A,B where A.id = B.id
2. select A.name, B.age from A join B on A.id = B.id
三:(右)外连接
1. select A.name, B.age from A,B where A.id(+) = B.id
2. select A.name, B.age from A right join B on A.id = B.id
四:(左)外连接
1. select A.name, B.age from A,B where A.id = B.id(+)
2. select A.name, B.age from A left join B on A.id = B.id
五:(满)外连接
1. select A.name, B.age from A full outer join B on A.id = B.id
TOP-N查询
select * from ( select * from A order by age desc ) where rownum <= 5 查询前5列
分页查询
select * from (select rownum as myno, A.* from (select * from B order by age desc) A)
where myno >=5 and myno <= 10
1. select A.name, B.age from A,B
2. select A.name, B.age from A cross join B
二:内连接
1. select A.name, B.age from A,B where A.id = B.id
2. select A.name, B.age from A join B on A.id = B.id
三:(右)外连接
1. select A.name, B.age from A,B where A.id(+) = B.id
2. select A.name, B.age from A right join B on A.id = B.id
四:(左)外连接
1. select A.name, B.age from A,B where A.id = B.id(+)
2. select A.name, B.age from A left join B on A.id = B.id
五:(满)外连接
1. select A.name, B.age from A full outer join B on A.id = B.id
TOP-N查询
select * from ( select * from A order by age desc ) where rownum <= 5 查询前5列
分页查询
select * from (select rownum as myno, A.* from (select * from B order by age desc) A)
where myno >=5 and myno <= 10
本文详细介绍了SQL中各种连接类型的应用场景与语法,包括交叉连接(笛卡尔积)、内连接、左外连接、右外连接及满外连接,并演示了TOP-N查询与分页查询的具体实现方式。
2064

被折叠的 条评论
为什么被折叠?



