Operators are a means by which SQL can manipulate numbers and strings or test for equality. They come infour flavors including: Arithmatic, Range, Equality, and Logical. As your skills with SQL grow, you may want thelanguage to start performing some basic arithmatic for you or perhaps you wish to select a range of rows with anumeric column value larger than 5. This becomes possible with operators.
SELECT * FROM
WHEREcolumn_one > 5;
are used in
. they show equality, inequality, or a combinationof both. Mathematical operators are found in every computer language and may be familiar to you. SQL operatorsfollow 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 tablesfor future reference.
SQL Arithmetic Operators:
+7 + 7= 14Addition-7 - 7= 0Subtraction*7 * 7= 49Multiplication/7 / 7= 1Division%7 % 7= 0ModulusModulus may be the only unfamiliar term on the chart. this term describes the result when one number isdivided by another number resulting in a remainder. For example 4 % 3 would result with a value of 1 since 1 is leftover after 4 is divided by 3.
SQL Range Operators:
<7 < 47 less than 4?False>7 > 4greater than 4?True<=7 <= 11Is 7 less than or equal to 11?True>=7 >= 11Is 7 greater than or equal to 11?False
SQL Equality Operators:
=5 = 5Is 5 equal to 5?True<>7 <> 2Is 7 not equal to 2?True
SQL Logical Operators:
ANDAssociates two values using ANDif (($x AND $y) == 5)...ORAssociates two values using ORif (($x OR $y) == 5)...
SQL - Expressions