请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册
  • 便民服务
  • 关注我们
  • 社区新手


CTRL +Q 新建一个窗口
ctrl +w 关闭窗口
注释  #注释/*-------*/
单行注释
两个表中字段的值相同时可以拼接
普通连接
去aa cc 两表的交集部分
select*from aa,cc where aa.id
注释  #
内连接
select*from aa inner join cc on aa.id=cc.s_id;
左连接 ;左边表中的数据符合的显示,右边表符合条件的显示不符合条件的为NULL,左边表中的数据全部显示,以左表我标准
select*from  aa left join cc on aa.id=cc.s_id;
右连接
select*from aa right join cc on aa.id=cc.s_id;
硬连接
5.硬连接--追加(2个表的字段数量必须相同)
1.基本连接
select aa.name,cc.score from aa,cc where aa.id=cc.s_id and aa.name="dc";
2.临时表
select t.name,t.score from(select * from aa,cc where aa.id=cc.s_id) as t WHERE t.name="dc";
3.嵌套方法"=" (=和in的区别,=只能是一个值,in后面可以是多个值)
select id from aa where name="dc";--先求出学号
select score from cc where cc.s_id=(select id from aa where name="dc");
嵌套方法"in"
select score from cc where cc.s_id in(select id from aa where name="dc");
求谁没参加考试?
第一种方法左连接
select aa.name from aa LEFT JOIN cc on aa.id=cc.s_id where score is null;
第二种方法右连接
select name from cc RIGHT JOIN aa on aa.id=cc.s_id where score is null;
第三种方法基本连接+嵌套
select id from aa,cc where aa.id=cc.s_id; ==》先求出已参加考试学号
SELECT name from aa where aa.id not in(select id from aa,cc where aa.id=cc.s_id);
第四种嵌套
SELECT name from aa where aa.id not in(select s_id from cc);
分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册