多表查询的分类,连接查询,内连接,外连接,交叉连接,子查询
9 多表查询的分类
连接查询:
内连接:inner join (inner 可以省略)
显示内连接:在SQL中显示调用了inner join关键字
Select * from 表1 inner join 表2 on 关联条件;
隐式内连接:在SQL中没有调用 inner join关键字
Select * from 表1,表2 where 关联条件
外连接:outer join (outer也是可以省略)
左外连接:select * from 表1 left outer join 表2 on 关联条件
右外连接:select * from 表1 right outer join 表2 on 关联条件
交叉连接 cross join 查询到的是两个表的笛卡尔积(第一个表和第二个表的每一个内容都连接,相当于全排列)
Select * from 表1 cross join 表2;
Cross join可以省略Select * from 表1,表2;
子查询:一个查询语句条件需要依赖另一个查询语句的结果。
10 交叉连接:
Select * from 表1 cross join 表2 ;(第一个表的每一条记录和第二表的每一个去匹配 结果数是:表一的行数*表2 的行数)
Select * from 表1,表2;(不使用 cross join关键字 ,结果是一样的 )
还没有评论,来说两句吧...