Reputation: 818
Well, pretty simple question I think, but I can't find a satisfying answer. Is there a difference between these two queries?
SELECT * FROM table WHERE column1 = 'x' OR column2 = 'x'
SELECT * FROM table WHERE (column1 = 'x' OR column2 = 'x')
Thanks in advance
Upvotes: 0
Views: 137
Reputation: 31627
Right now there is NO difference in your queries.
There would be difference if there would be AND
condition as addition in your query.
e.g
SELECT * FROM table WHERE id=1 AND column1 = 'x' OR column2 = 'x'
and
SELECT * FROM table WHERE id=1 AND (column1 = 'x' OR column2 = 'x')
SELECT * FROM table WHERE id=1 AND column1 = 'x' OR column2 = 'x'
would be equivalent to
SELECT * FROM table WHERE (id=1 AND column1 = 'x') OR column2 = 'x'
Upvotes: 2
Reputation: 20745
The role of parenthesis will be usefull when there is one more condition with AND operator. otherwise no difference in execution plan except syntax.
Upvotes: 3
Reputation: 125835
Further to my comment above, the manual explains:
Some of the optimizations performed by MySQL follow:
Removal of unnecessary parentheses:
((a AND b) AND c OR (((a AND b) AND (c AND d)))) -> (a AND b AND c) OR (a AND b AND c AND d)
So no, there is no difference whatsoever.
Upvotes: 2
Reputation: 8614
No. its the same. As long as there are only two conditions braces doesn't have much significance.
Upvotes: 1