关于SQL查询效率比较
来源:百度知道 编辑:UC知道 时间:2024/05/17 07:24:34
1. select * from a,b where a.id=b.id;
2. select * from a join b on a.id=b.id;
3. select * from a left join b on a.id=b.id where b.col is not null;
4. select * from a right join b on a.id=b.id where a.col is not null;
哪条效率最高?
2. select * from a join b on a.id=b.id;
3. select * from a left join b on a.id=b.id where b.col is not null;
4. select * from a right join b on a.id=b.id where a.col is not null;
哪条效率最高?
要看sql的执行效率,可以看数据库的执行计划,和数据情况
这四条语句都是比较简单的,但从Explain plan来看,他们差不多,但根据数据情况来看,第一条速度最快
第一个
第一个和第二个是一样的,选择一和二