Reputation: 9378
I want to delete 2 distict rows, but with simular data. 3 colums, 1 is unique, and the other 2 are switched around. I was using something like this but it only delete 1.
DELETE FROM Table
WHERE Column1 = 'a' AND Column2 = 'b'
OR column1 = 'b' AND Column2 = 'a'
This only deleted one column the statement. Thanks for any help
Upvotes: 1
Views: 153
Reputation: 76557
In SQL AND
takes preference over OR
.
Your where
clause is interpreted as
WHERE (Column1 = 'a')
AND (Column2 = 'b' OR column1 = 'b')
AND (Column2 = 'a')
This is quite likely not what you want and you should (almost) always put the OR'ed tests in parenthesis like so:
WHERE (Column1 = 'a' AND Column2 = 'b')
OR (column1 = 'b' AND Column2 = 'a')
See: http://dev.mysql.com/doc/refman/5.0/en/operator-precedence.html
Upvotes: 3