Reputation: 3481
I'm trying to use a SELECT
statement and fetch all rows from a table except for one which has an id
of 4
- is there a simple way to do this?
Upvotes: 18
Views: 51280
Reputation: 5822
You have a few options:
SELECT * FROM table WHERE id != 4;
SELECT * FROM table WHERE NOT id = 4;
SELECT * FROM table WHERE id <> 4;
Also, considering perhaps sometime in the future you may want to add/remove id's to this list, perhaps another table listing id's which you don't want selectable would be a good idea.
In which case you would have:
SELECT * FROM table
WHERE id NOT IN (SELECT id FROM exempt_items_table);
Upvotes: 42