SQL Tutorial 7: SQL Operators
An operator is a reserved give-and-take or a grapheme used primarily inwards an SQL statement's WHERE clause to perform operation(s), such equally arithmetic, comparisons as well as Logical operations.
Operators are used to specify weather condition inwards an SQL tilt as well as to serve as
conjunctions for multiple weather condition inwards a statement.
Important Categories of SQL Operators are,
1) Arithmetic operators
2) Comparison operators
3) Logical operators Etc...
---------------------------
1) Arithmetic Operators:
Arithmetic operators tin perform arithmetical operations on numeric operands
involved.
Operator Description
+ Add
- Subtract
* Multiply
/ Division
% Modulus
Examples:
i) Add (+)
SELECT thirty + 20;
ii) Subtract (-)
SELECT thirty - 20;
iii) Multiply (*)
Select thirty * 20;
iv) Division
Select xl / 20;
v) Modulus (%)
Select xl % 19;
---------------------------
2) Comparison Operators:
A comparing (or relational) operator is a mathematical symbol which is used to
compare betwixt 2 values.
Comparison operators are used inwards weather condition that compare 1 seem with
another. The number of a comparing tin move TRUE, FALSE, or UNKNOWN
(an operator that has 1 or 2 NULL expressions returns UNKNOWN).
The next tabular array describes dissimilar types of comparing operators
Operator Description
= Equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
<> Not equal to
Examples:
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 3 Logical Operators namely, AND, OR, as well as NOT. These operators
compare 2 weather condition at a fourth dimension to cause upwards one's hear whether a row tin move selected for the output. When retrieving information using a SELECT statement, You tin purpose logical operators inwards the WHERE clause, which allows yous to combine more than 1 condition.
Operator Description
ALL TRUE if all of the sub-query values encounter the condition
AND TRUE if all the weather condition separated past times AND is TRUE
ANY TRUE if whatever of the sub-query values encounter the condition
BETWEEN TRUE if the operand is inside the arrive at of comparisons
EXISTS TRUE if the sub-query returns 1 or to a greater extent than records
IN TRUE if the operand is equal to 1 of a listing of expressions
LIKE TRUE if the operand matches a designing Try it
NOT Displays a tape if the condition(s) is NOT TRUE
OR TRUE if whatever of the weather condition separated past times OR is TRUE
SOME TRUE if whatever of the sub-query values encounter the condition
Examples:
i) And
Select * From abcd
Where Age > 25 And City ='Hyderabad';
ii) Or
Select * From abcd
Where Age > xl Or City ='Pune';
iii) Between
Select * From abcd
----------------------------------------------------
An operator is a reserved give-and-take or a grapheme used primarily inwards an SQL statement's WHERE clause to perform operation(s), such equally arithmetic, comparisons as well as Logical operations.
Operators are used to specify weather condition inwards an SQL tilt as well as to serve as
conjunctions for multiple weather condition inwards a statement.
Important Categories of SQL Operators are,
1) Arithmetic operators
2) Comparison operators
3) Logical operators Etc...
---------------------------
1) Arithmetic Operators:
Arithmetic operators tin perform arithmetical operations on numeric operands
involved.
Operator Description
+ Add
- Subtract
* Multiply
/ Division
% Modulus
Examples:
i) Add (+)
SELECT thirty + 20;
ii) Subtract (-)
SELECT thirty - 20;
iii) Multiply (*)
Select thirty * 20;
iv) Division
Select xl / 20;
v) Modulus (%)
Select xl % 19;
---------------------------
2) Comparison Operators:
A comparing (or relational) operator is a mathematical symbol which is used to
compare betwixt 2 values.
Comparison operators are used inwards weather condition that compare 1 seem with
another. The number of a comparing tin move TRUE, FALSE, or UNKNOWN
(an operator that has 1 or 2 NULL expressions returns UNKNOWN).
The next tabular array describes dissimilar types of comparing operators
Operator Description
= Equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
<> Not equal to
Examples:
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 3 Logical Operators namely, AND, OR, as well as NOT. These operators
compare 2 weather condition at a fourth dimension to cause upwards one's hear whether a row tin move selected for the output. When retrieving information using a SELECT statement, You tin purpose logical operators inwards the WHERE clause, which allows yous to combine more than 1 condition.
Operator Description
ALL TRUE if all of the sub-query values encounter the condition
AND TRUE if all the weather condition separated past times AND is TRUE
ANY TRUE if whatever of the sub-query values encounter the condition
BETWEEN TRUE if the operand is inside the arrive at of comparisons
EXISTS TRUE if the sub-query returns 1 or to a greater extent than records
IN TRUE if the operand is equal to 1 of a listing of expressions
LIKE TRUE if the operand matches a designing Try it
NOT Displays a tape if the condition(s) is NOT TRUE
OR TRUE if whatever of the weather condition separated past times OR is TRUE
SOME TRUE if whatever of the sub-query values encounter the condition
Examples:
i) And
Select * From abcd
Where Age > 25 And City ='Hyderabad';
ii) Or
Select * From abcd
Where Age > xl Or City ='Pune';
iii) Between
Select * From abcd
----------------------------------------------------