随笔分类 -  数据库

摘要:第一篇博客,就写下今天遇到的sql优化的问题吧。not in效率很差,因为需要2表全表检索(单表情况),而且没有用到表索引,替代写法可以用外连接:select a.* from A awhere a.id not in(select b.id from B b)替代:select a.* frm A aleft join B b on a.id = b.idwhere b.id is null也可以not existsselect a.* from A a not exists (select b.* from B b where b.id = a.id)另外,前几天面试被问到的:union和 阅读全文
posted @ 2013-10-29 21:48 YANGGN_SEU 阅读(715) 评论(1) 推荐(1)