表关联查询

一 表关联查询
   1.表的关联分两类
       有关系的关联
       无关系的关联
   2.表的有关系的关联(内关联)
where 指定关联关系
表1.字段=表2.字段 and 表2.字段=表3.字段
有关系关联:
   通过字段关系,把多张表合并在一起.
select s_emp.id,first_name,name from s_emp,s_dep
where s_emp.dep_id=s_dept.id;
//
select s_emp.id,firs_name,name from s_emp
inner join s_dept on (s_emp.dept_id=s_dpt.id);
选择字段:*
字段列表
表.字段列表
表.*,字段
   3.外关联:(outer join)
左关联(left outer join) 以哪个表字段为主而定义
右关联(right outer join)
完全关联(full outer join)
      外关联与内关联语法
delete from s_emp where id>25;
select s_emp.id,first_name,s_dept.id,name from s_emp,s_dept
//where s_emp.dept_id=s_dept.id(+);表示把这个表关联到左边
 right outer joins_dept on (s_emp.dept_id=s_dpt.id);
//where s_emp.dept_id(+)=s_dept.id; 
 left outer joins_dept on (s_emp.dept_id=s_dpt.id);
 full outer joins_dept on (s_emp.dept_id=s_dpt.id);
   4.自关联:
 select e.id,e.first_name,m.first_name from s_emp as e,s_emp as m
 where e.manager_id=m.id;
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值