开发者

what's the best technique for selecting records with long comparison in where clause

Say, I need to select records from a table and exclude records with id 1,2,5,9,15. I do th开发者_开发技巧is:

"SELECT * FROM TABLE_NAME WHERE id <> 1 OR id <> 2 OR id <> 5 OR id <> 9 OR id <> 15"

But what if I have like 1000 records and I need to exclude 200 records? Would I have to type 200 " OR id <> id_number"? Or is there a better way to do the query?


Try:

SELECT * FROM TABLE_NAME WHERE id NOT IN (1, 2, 5, 9, 15)


You can maybe exclude a range. Instead of id<>1 OR id<>2 .. id<>5 you can do : id<1 AND id>5. and you can check the "where id not in (1, 2, 3 ...)" option

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜