SQL Operators

SQL Tutorial, SQL Language Elements, Arithmetic operators, Comparison operators, Logical operators, and usage of operators in SQL statements.

SQL Operators

An operator is a reserved word or a character used primarily in an SQL statement’s WHERE clause to perform an operation(s), such as arithmetic, comparisons, and Logical operations.

Operators are used to specifying conditions in an SQL statement and to serve as conjunctions for multiple conditions in a statement.

Important Categories of SQL Operators are,

1. Arithmetic operators
2. Comparison operators
3. Logical operators Etc…

1. Arithmetic Operators:

Arithmetic operators can perform arithmetical operations on numeric operands involved.

Operator Description

+                  Add
–                  Subtract
*                  Multiply
/                  Division
%                Modulus


i. Add (+)
SELECT 30 + 20;

ii. Subtract (-)
SELECT 30 – 20;

iii. Multiply (*)
Select 30 * 20;

iv. Division
Select 40 / 20;

v. Modulus (%)
Select 40 % 19;

2. Comparison Operators:

A comparison (or relational) operator is a mathematical symbol that is used to compare between two values.

Comparison operators are used in conditions that compare one expression with another. The result of a comparison can be TRUE, FALSE, or UNKNOWN (an operator that has one or two NULL expressions returns UNKNOWN).

The following table describes different types of comparison operators

Operator Description

=                  Equal to
>                  Greater than
<                  Less than
>=                Greater than or equal to
<=               Less than or equal to
<>               Not equal to


i. Select * From abcd
Where City=’Pune’;

ii. Select * From abcd
Where Age > 25;

iii. Select * From abcd
Where Age >= 25;

iv. Select * From abcd
Where Age < 25;

v. Select * From abcd
Where Age <= 25;

vi. Select * From abcd
Where Age <> 25;

3. Logical Operators:

There are three Logical Operators namely, AND, OR, and NOT. These operators compare two conditions at a time to determine whether a row can be selected for the output. When retrieving data using a SELECT statement, You can use logical operators in the WHERE clause, which allows you to combine more than one condition.

ALL TRUEif all of the sub-query values meet the condition
AND TRUEif all the conditions separated by AND is TRUE
ANY  TRUEif any of the sub-query values meet the condition
BETWEEN TRUEif the operand is within the range of comparisons
EXISTS TRUEif the sub-query returns one or more records
IN TRUEif the operand is equal to one of a list of expressions
LIKE TRUEif the operand matches a pattern Try it
NOT Displays a record if the condition(s) is NOT TRUE
OR TRUE if any of the conditions separated by OR is TRUE
SOME TRUE if any of the sub-query values meet the condition


i. And
Select * From abcd
Where Age > 25 And City =’Hyderabad’;

ii. Or
Select * From abcd
Where Age > 40 Or City =’Pune’;

iii. Between
Select * From abcd

SQL Syllabus
SQL Queries for Software Testers
SQL Step by Step Tutorial – Full Course for Beginners
Manual Testing Tutorial
Java Tutorial
Python Tutorial
Follow me on social media: