The SQL query using a IN (list) is really successful and is very fast, avoiding having to loop over each item.The trick is to format the SQL as a string and surround it with round brackets " ID IN (1,2,3)"If the item is a string then you have to surround each element with single quotes "CODE IN ('1','2','3')"[Note that if you use "normal" field names without spaces special characters etc etc then you do not need to surround the field name with double quotes, making expression assembly easier]I recommend that you create the expression as a string and print it out to check for debugging.Then the error message has an easy feedback and you will see your logic error easily.#
NearFIDlst = [33950, 7700, 4340]
sqlQuery = "FID in (" + ','.join([str(x) for x in NearFIDlst]) +")"
print sqlQuery
codelst = ["abc","xyz","123"]
sqlQuery2 = "CODE in (" + ','.join(["'"+x+"'" for x in codelst]) +")"
print sqlQuery2
FID in (33950,7700,4340)
CODE in ('abc','xyz','123')