[MySQL]使用EXISTS代替IN
时间:2021-07-01 10:21:17
帮助过:6人阅读
-> 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