exist和in的区别
exist和in的区别:
select * from a where id in(select id from b);
select * from a where exists(select 1 from b where id=a.id);
差别较大;
使用in ,sql语句是先执行子查询,也就是先查询b表,在查a表,
而使用exists是先查主表a ,再查字表b;
对于主表数据较多时,我们使用in速度比exist更快,反之,从表b较大时,使用exist插叙速度更快(都会使用索引),如果使用的是not in与not exists,直接使用not exists,因为not in 会进行全表扫描不走索引,not exists会走索引。
一个是性能,另一个就是Not 的情况,not的话,我还是建议用esists。
第二种速度更快,但没写对,应该这么写
select * from a where exists(select 1 from b where id=a.id);
学习
exist和in的区别
exist和in的区别:select * from a where id in(select id from b); select * from a where exists(select 1 from ...
点击下载文档
本文2024-09-16 17:26:55发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-15764.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
- 鼎捷EAI整合規範文件V3.1.07 (集團).pdf
- 鼎捷OpenAPI應用場景說明_基礎資料.pdf
- 鼎捷OpenAPI應用場景說明_財務管理.pdf
- 鼎捷T100 API設計器使用手冊T100 APIDesigner(V1.0).docx
- 鼎新e-GoB2雲端ERP B2 線上課程E6-2應付票據整批郵寄 領取.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程A4使用者建立權限設定.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程C3會計開帳與會計傳票.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程E6-1應付票據.pdf
- 鼎新e-GoB2雲端ERP B2 線上課程A5-1進銷存參數設定(初階篇).pdf
- 鼎新e-GoB2雲端ERP B2 線上課程D2帳款開帳與票據開帳.pdf
热门文章