Isaac
Isaac

Reputation: 39

SQL Deleting rows based on two or more columns

I am trying to delete from my table all rows where the 'ID' column is NULL, except for the rows where the the 'group column is 'Everyone'. How can I do this? I have tried different combinations of the above query and none of them have worked.

delete from LANReporter where NOT [Group] = 'everyone' AND [ID] IS NULL AND 
[Server] = 'sv73938'

Upvotes: 0

Views: 239

Answers (4)

Md. Suman Kabir
Md. Suman Kabir

Reputation: 5453

You can use this :

delete LANReporter where [Group] <> 'everyone' AND [ID] IS NULL AND 
[Server] = 'sv73938'

Upvotes: 0

Tab Alleman
Tab Alleman

Reputation: 31775

If Group can be NULL you need to do this:

WHERE (Group IS NULL OR [Group] <> 'everyone') AND [ID] IS NULL AND 
[Server] = 'sv73938'

Upvotes: 1

Tranquillity
Tranquillity

Reputation: 367

You can try this

delete from LANReporter where [id] is null and [group] not in ('everyone') and [Server] = 'sv73938';

Upvotes: 0

JNevill
JNevill

Reputation: 50019

Use the "Not Equal To" condition !=:

  DELETE FROM LANReporter 
  WHERE [Group] != 'everyone'
      AND [ID] IS NULL
      AND [Server] = 'sv73938';

If this still doesn't do the trick, then I suspect you have issues in your data (perhaps your NULL's aren't actually NULL but rather empty strings, or whitespace).

Upvotes: 0

Related Questions