SQL - Operators
Operators are used in expressions or conditional statements. they show equality, inequality, or a combination of both. Mathematical operators are found in every computer language and may be familiar to you. SQL operators follow the same rules you may have learned in a math class or know from previous programming experience.
Operators come in three flavors, mathematical, logical, or range operations. Mathematical operators add, subtract, multiply, divide, and compare equality of numbers and strings. There are two logical operators, AND / OR. Range operators include the infamous < and > symbols used to compare equality. Take note of the following tables for future reference.
SQL Arithmetic Operators:
| Operator | Example | Result | Definition |
| + | 7 + 7 | = 14 | Addition |
| - | 7 - 7 | = 0 | Subtraction |
| * | 7 * 7 | = 49 | Multiplication |
| / | 7 / 7 | = 1 | Division |
| % | 7 % 7 | = 0 | Modulus |
Modulus may be the only unfamiliar term on the chart. this term describes the result when one number is divided by another number resulting in a remainder. For example 4 % 3 would result with a value of 1 since 1 is left over after 4 is divided by 3.
SQL Range Operators:
| Operator | Example | Defined | Result |
| < | 7 < 4 | 7 less than 4? | False |
| > | 7 > 4 | greater than 4? | True |
| <= | 7 <= 11 | Is 7 less than or equal to 11? | True |
| >= | 7 >= 11 | Is 7 greater than or equal to 11? | False |
SQL Equality Operators:
| Operator | Example | Defined | Result |
| = | 5 = 5 | Is 5 equal to 5? | True |
| <> | 7 <> 2 | Is 7 not equal to 2? | True |
SQL Logical Operators:
| Operator | Defined | Example |
| AND | Associates two values using AND | if (($x AND $y) == 5)... |
| OR | Associates two values using OR | if (($x OR $y) == 5)... |
|