0

I'm trying to accomplish basically this:

Select * FROM x WHERE id != for(int i : arraylist)

So basically I have an arraylist with say 10 ids, I want the sql not to return any of the rows that have an ID the same as in my arraylist, and I'd rather not do it with like 10 queries. Is there any way to do this?

2 Answers 2

3

You're looking for the SQL IN keyword:

SELECT * FROM x WHERE id NOT IN ( 1, 2, 3, etc. )
Sign up to request clarification or add additional context in comments.

Comments

1

in this way:

SELECT * FROM x WHERE id not in ( list of value ) // i.e. 'A', 'B', ...

Pay attention: You can execute this statement only if yuo array has been filled.

If you have an array with no items NOT IN can cause problems.

So, you must check your condition before put NOT IN clause.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.