简体   繁体   中英

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 this:

"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?

尝试:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM