1.内连接查询语法
注:内连接相当于查询表A,B之间交集的数据
隐式内连接:
select 字段列表 from 表1,表2…… where 条件;
显示内连接:
select 字段列表 from 表1 [inner] join 表2 on 条件;
隐式内连接:
例如:select * from emp,dept where emp.dep_id =dept.id;
在表emp,dept中查找到emp.dep_id和dept.id相同的所有内容
select emp.name,emp.id,dept.id from emp,dept where emp.dep_id=dept.id;
同上,但这种方法只查找emp.name、emp.id、dept.id,而不是查找全部内容
显示内连接:
例如:select * from emp inner join dept on emp.dep_id = dep.id;
上述字段与隐式内连接相同
2.外连接查询语法
注:左外连接会查询出表1所有数据以及交集数据
右外连接同理
左外连接:
select 字段列表 from 表1 left [outer] join 表2 on 条件
右外连接:
select 字段列表 from 表1 right [outer] join 表2 on 条件
注:outer 可省略