mysql 查询一张表没有存在在另一张表的数据
2016-03-11 14:05
701 查看
student表
id
name
1 张三
2 李四
3 王五
4 赵四
result表
id score
1 80
2 60
查询没有考试成绩的学生
方法1:
select *
from student
where id
not
in
(select id
from result)
方法2:
select
* from
student where
not exists
(select 1
from result
where result.id= student.id
)
方法3:
select
student.* from
student left join
result on
(studeng.id = result.id) where
result.id is null
id
name
1 张三
2 李四
3 王五
4 赵四
result表
id score
1 80
2 60
查询没有考试成绩的学生
方法1:
select *
from student
where id
not
in
(select id
from result)
方法2:
select
* from
student where
not exists
(select 1
from result
where result.id= student.id
)
方法3:
select
student.* from
student left join
result on
(studeng.id = result.id) where
result.id is null
相关文章推荐
- MYSQL数据库隔离级别分析
- mysql in 子查询 效率慢 优化
- mysql中or和in的效率问题
- mysql删除数据库
- mysql 主主配置
- 解决Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future:
- 转:MySQL 的show processlist
- MySQL5.7压缩版安装配置
- 基于Hibernate的动态查询(HQL、Criteria、DetachedCriteria、MySQL)
- MySQL安装以及MySQL的备份和恢复
- 修改mysql 默认字符集 , 默认引擎
- Ubuntu上安装MySQL+问题处理+安全优化
- MySql_DB_Connection_AutoCommit
- mysql 碎片清理
- MySQL Innodb 插入调优
- MySQL 二进制日志(Binary Log)
- mysql复制环境清理二进制日志
- not allowed to connect to this mysql server
- 从一个问题看MySQL的权限访问控制
- 删除mysql 安装 mysql 5.1.65 5.1.73