Summing and comparing with or without parentheses
I have 3 columns which are of type double.
I need to get results where the sum these of 3 columns is more than x.
Maybe a dumb question, which of the following methods is better for this
1) Usually summing: WHERE col1 + col2 + col3 > x
2) Or summing in parentheses: WHERE (col1 + col2 + col3) > x
Or there is absolutely no difference between the two menthods ?
Your both query has no problem.By operator hierarchies it would be better to use parenthesis method.
Operator precedences are shown in the following list, from highest precedence to the lowest. Operators that are shown together on a line have the same precedence.
INTERVAL BINARY, COLLATE ! - (unary minus), ~ (unary bit inversion) ^ *, /, DIV, %, MOD -, + <<, >> & | = (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN BETWEEN, CASE, WHEN, THEN, ELSE NOT &&, AND XOR ||, OR = (assignment), := Its better to handle the summarized values among three columns.
WHERE (col1 + col2 + col3) > x