标签: mysql
我知道我可以排除这样的行:
SELECT * FROM products WHERE id <>1
但我需要排除2件产品,我已尝试过:
SELECT * FROM products WHERE id <>(1,2)
但没有运气。
答案 0 :(得分:3)
试试这个
SELECT * FROM products WHERE id not in (1,2)
IN肯定比OR快。见MYSQL OR vs IN performance
IN
OR
答案 1 :(得分:0)
使用NOT:
NOT
SELECT * FROM `products` WHERE `id` NOT IN (1, 2);
性能方面,IN比比较快!