user1163278
user1163278

Reputation: 421

MySQL: select from table excluding where parameter

I'm trying to select from table, excluding where id is something, say 7.

I have tried: SELECT * FROM table where not exists(select * from table where user_id = '7');

Could anyone direct my to a place where I could get info on this?

Upvotes: 0

Views: 6621

Answers (2)

Mike Purcell
Mike Purcell

Reputation: 19989

You can do:

SELECT * FROM your_table WHERE id NOT IN(7);

You can find more comparison operators via the Mysql Docs on the subject.

Upvotes: 4

JYelton
JYelton

Reputation: 36512

You can invert equality in your WHERE condition, like this:

SELECT field FROM table WHERE id != 7;

Upvotes: 0

Related Questions