Web www.tizag.com

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:

OperatorExampleResultDefinition
+7 + 7= 14Addition
-7 - 7= 0Subtraction
*7 * 7= 49Multiplication
/7 / 7= 1Division
%7 % 7= 0Modulus

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:

OperatorExampleDefinedResult
<7 < 47 less than 4?False
>7 > 4 greater 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:

OperatorExampleDefinedResult
=5 = 5Is 5 equal to 5?True
<>7 <> 2Is 7 not equal to 2?True

SQL Logical Operators:

OperatorDefinedExample
ANDAssociates two values using ANDif (($x AND $y) == 5)...
ORAssociates two values using ORif (($x OR $y) == 5)...




New - Tizag.com Forums!
Recent Forum Topics: