MySQL Operators

Good Day!!!

In this tutorial, we are going to learn about the MySQL Operators and this is the continuation of MySQL Tutorials. My last work was all about the MySQL Reserved Words. In this Chapter, we will know all kinds of Operators in MySQL.

Operator Precedence

Operators which are shown below, in a line together will they have the same precedence. The precedence in operators, has a rules and you will shown from highest to lowest precedence.
  1. !
  2. - (unary minus), ~ (unary bit inversion)
  3. ^
  4. *, /, DIV, %, MOD
  5. -, +
  6. <<, >>
  7. &
  8. |
  9. = (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN
  10. &&, AND
  11. ||, OR
  12. = (assignment), :=
In the the table above, it all determines the order of evaluation of terms in an expression.
Example:
  1. mysql> SELECT 10+10*40;
  2.         -> 410
  3. mysql> SELECT (10+20)*30;
  4.         -> 900

Arithmetic Operators

Arithmetic Operators perform basic arithmetic on two values, which are shown below and this operators supported in MySQL:
  1. +       Adds two numerical values
  2. -       Subtracts two numerical values
  3. /       Divides two numerical values
  4. *       Multiplies two numerical values
  5. %       Gives the modulo of two numerical values
  6. |       Performs OR on two integer values
  7. ^       Performs exclusive OR on two integer values
  8. &       Performs  AND on two integer values
  9. <<      Performs  left shift on an integer value
  10. >>      Performs right shift on an integer value

Comparison Operators

Comparison operators compare values and return 1 if the comparison is true and 0 otherwise. This operators also supported in MySQL.
  1. =       Equals to
  2. <       if the left value is less than the right value
  3. >       if the left value is greater than the right value
  4. <=      if the left value is less than or equal to the right value
  5. >=      if the left value is greater than or equal to the right value
  6. < >, != if the two values are not equal
  7. Between Checks the mentioned limits
  8. Greatest        Finds the greatest value

Logical Operators

Logical Operators in SQL terms, checks whether its operands are 0, nonzero or NULL. The 0 value means false, nonzero means true and NULL means no value. This kind of operators check the truth value of one or more expressions, which are shown below and this operators supported in MySQL:
  1. NOT or !        not (returns "1" if the value is 0, NULL if it is NULL, otherwise "0")
  2. OR or ||        or (returns "1" if any of the arguments are nonzero and non-NULL, NULL if any are NULL; otherwise, returns "0")
  3. XOR             logical exclusive or (returns "1" if one and only on argument is nonzero and non-NULL, NULL if any are NULL; otherwise. returns "0")
  4. AND or &&       and (returns "0" if any of the arguments are 0, NULL if any are NULL; otherwise, returns "1")
For my next tutorial lets discuss the "MySQL Programs". So what can you say about this tutorial? Share your thoughts in the comment section below and also, don’t forget to like this page. Thank you.

Add new comment