简体   繁体   中英

How to handle array values in sql query

I have a personID array like this (123,456,789,etc...) What I want to do is to query like this SELECT * FROM tblperson WHERE personID <> '123' or personID <> '456' or personID <> '789'

Note that the personID i want to get is from dynamic array. Thanks!

Use not in

SELECT * FROM tblperson WHERE personID not in ( 123 ,456 , 789)

As you are using javascript, try below code to generate your query

var ids = [123 ,456 , 789];
var query = 'SELECT * FROM table WHERE id not IN (' + ids.join() + ')';

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