# SQL – Operators & Expressions

### SQL Operators:

The symbols which are used to perform logical and mathematical operations in SQL are called SQL operators. There are three types of Operators used in SQL. They are,

1. Arithmetic operators
2. Relational operators
3. Logical operators

### 1. ARITHMETIC OPERATORS in SQL:

Arithmetic operators in SQL are used to perform mathematical calculations like addition, subtraction, multiplication, division and modulus in SQL statements.

 Arithmetic Operators/Operation Example + (Addition) A+B – (Subtraction) A-B * (multiplication) A*B / (Division) A/B % (Modulus) A%B

### 2. RELATIONAL OPERATORS in SQL:

Relational operators in SQL are used to find the relation between two columns. i.e. to compare the values of two columns in SQL statements.

 Operators Example/Description > x > y (x is greater than y) < x < y (x is less than y) >= x >= y (x is greater than or equal to y) <= x <= y (x is less than or equal to y) = x == y (x is equal to y) != or < > x != y or x <> y (x is not equal to y) !< x !< y (x is not less than y) !> x !> y (x is not greater than y)

### 3. LOGICAL OPERATORS in SQL:

Logical operators in SQL are used to perform logical operations on the given expressions in SQL statements. There are many operators in SQL which are used in SQL statements in the WHERE clause. They are,

• AND
• OR
• NOT
• BETWEEN…AND
• IS NULL, IS NOT NULL
• LIKE
• UNIQUE
• In, NOT IN etc.

Please go through this SQL tutorial to know about each operator and its functionality.

### SQL – Expressions:

SQL operators join table columns, SQL functions and constants together to form expressions in SQL.

• Consider the following expression A + B * 5;
Where,
+, * are operators
A, B  are variables
5 is constant
A + B * 5 is an expression
• Consider the following expression SUM(column1+column2)* 5 > 250;
Where,
SUM(column1+column2) – SQL function
5 is constant and
> is a relational operator
SUM(column1+column2)* 5 > 250 is an expression

Example for Expressions in SQL query:

 Syntax for SQL WHERE clause SELECT column_name1, column_name2, etc FROM table_name WHERE  [condition/Expression];

[condition/Expression] should be in the following format.

[column_name] [Operator] [Value];

Where
[column_name] – Any one of the column names in the table
[Operator] – Any one of the following (>, <, =, >=, <=, NOT, LIKE etc)
[Value] – User defined value