Is there a difference between these two queries?

前端 未结 5 1450
走了就别回头了
走了就别回头了 2020-12-22 08:32

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 colum         


        
相关标签:
5条回答
  • 2020-12-22 09:08

    No, there's not a single difference.

    See more MySQL Syntax here.

    0 讨论(0)
  • 2020-12-22 09:13

    The role of parenthesis will be usefull when there is one more condition with AND operator. otherwise no difference in execution plan except syntax.

    0 讨论(0)
  • 2020-12-22 09:17

    No. its the same. As long as there are only two conditions braces doesn't have much significance.

    0 讨论(0)
  • 2020-12-22 09:20

    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.

    0 讨论(0)
  • 2020-12-22 09:21

    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')
    

    Note

    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'
    

    Hope you get the difference.

    0 讨论(0)
提交回复
热议问题