From the course: MySQL Essential Training

Unlock this course with a free trial

Join today to access over 23,200 courses taught by industry experts.

Operator precedence

Operator precedence

- [Bill] Hi, I am Bill Weinman. If you have an expression with more than one operator, it can be valuable to understand the order in which the operators will be evaluated. This is called operator precedence. For example, if I say SELECT 5 plus 6 times 7 minus 8, I get a result that says 39. But if I put parentheses around the 5 plus 6 and the 7 minus 8, that forces the addition and subtraction to be processed before the multiplication, and when I execute that, you notice I get minus 11, an entirely different result. This is because the parentheses have forced the system to evaluate the expressions in a different order. If instead, I put the parentheses around the 6 times 7, then you notice we get our original result of 39. It's exactly the same as if I did not have the parentheses, and I'll go ahead and execute that again. And you can see this is because multiplication already has a higher precedence than addition or subtraction. A common way to remember the precedence of most common…

Contents