From the course: MySQL Essential Training (2019)

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Arithmetic operators

Arithmetic operators

- [Instructor] MySQL provides a complete set of arithmetic operators. For example, select five plus three and execute. And we see the result is eight, as expected. Five minus three is two. Five times three is 15. And five divided by three is 1.66 et cetera. Five divided by three is different than five DIV three, which is one. That's an integer result, so to get the remainder, you use the modulus operator, which is M-O-D. And that'll give us the remainder of two. You may also use the percent symbol as the modulus operator. And that gives you the same result. The percent symbol is specific to MySQL. It is not the SQL standard. And in MySQL, division by zero results in a null result. Keep in mind the result of five divided by zero is going to be different on different platforms and on different systems. But in MySQL, it results in null. So the arithmetic operators are both intuitive and functionally complete.

Contents