码迷,mamicode.com
首页 > 数据库 > 详细

[MySQL]使用EXISTS代替IN

时间:2017-10-26 16:13:22      阅读:377      评论:0      收藏:0      [点我收藏+]

标签:log   not   where   from   style   class   weight   使用   mys   

#IN -> EXISTS
SELECT * FROM CouponItem AS A WHERE A.CouponId IN(SELECT B.Id FROM Coupon AS B WHERE B.Id<30);
SELECT * FROM CouponItem AS A WHERE EXISTS(SELECT B.Id FROM Coupon AS B WHERE B.Id<30 AND A.CouponId=B.Id);

#NOT IN -> NOT EXISTS
SELECT * FROM CouponItem AS A WHERE A.CouponId NOT IN(SELECT B.Id FROM Coupon AS B WHERE B.Id<30);
SELECT * FROM CouponItem AS A WHERE NOT EXISTS(SELECT B.Id FROM Coupon AS B WHERE B.Id<30 AND A.CouponId=B.Id);

[MySQL]使用EXISTS代替IN

标签:log   not   where   from   style   class   weight   使用   mys   

原文地址:http://www.cnblogs.com/xiaowangzhi/p/7737254.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!