user516883
user516883

Reputation: 9378

delete 2 rows 1 Sql statement mysql

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

Answers (1)

Johan
Johan

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

Related Questions