Reputation: 2898
I need a little help with SQL, so basically what I want to achieve is to select everything in a table except where the code is 1,2 and 3. It works with one number but I can't figure out how to select it with three numbers.
My SQL statement so far:
SELECT * FROM images WHERE round='$round' and code != 1
Upvotes: 0
Views: 692
Reputation: 424993
The strict way is:
SELECT *
FROM images
WHERE round = '$round'
and code not in (1, 2, 3)
But if code values are not negative, your example may be coded as simply:
SELECT *
FROM images
WHERE round = '$round'
and code > 3
Upvotes: 0
Reputation: 262
if such specific data, this script is more efficient
SELECT * FROM images WHERE round='$round' and (code < 1 or code > 3)
Upvotes: 0
Reputation: 49049
SELECT *
FROM images
WHERE
round='$round' and
code NOT IN (1,2,3)
or:
SELECT *
FROM images
WHERE
round='$round'
AND NOT (code=1 OR code=2 OR code=3)
Upvotes: 2