SQL Tutorial 7: SQL Operators
SQL Tutorial 7: SQL Operators
An operator is a reserved word or a character used primarily in an SQL statement’s WHERE clause to perform operation(s), such as arithmetic, comparisons and Logical operations.
Operators are used to specify 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
Examples:
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 which 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
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;
—————————

SQL Operators Tutorial
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.
Operator Description
ALL TRUE if all of the sub-query values meet the condition
AND TRUE if all the conditions separated by AND is TRUE
ANY TRUE if any of the sub-query values meet the condition
BETWEEN TRUE if the operand is within the range of comparisons
EXISTS TRUE if the sub-query returns one or more records
IN TRUE if the operand is equal to one of a list of expressions
LIKE TRUE if 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
Examples:
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 Step by Step Tutorials
https://www.gcreddy.com/2016/08/sql-tutorials.html
SQL Tutorial 1: Introduction to SQL
https://www.gcreddy.com/2016/07/introduction-to-sql.html
SQL Tutorial 2: SQL Overview
https://www.gcreddy.com/2016/08/sql-overview.html
SQL Tutorial 3: SQL Environment Setup
https://www.gcreddy.com/2016/09/sql-environment-setup.html
SQL Tutorial 4: Database Fundamentals and SQL Language Elements
https://www.gcreddy.com/2016/11/database-fundamentals-and-sql-language.html
SQL Tutorial 5: Data Definition Language
https://www.gcreddy.com/2016/11/sql-data-definition-language.html
SQL Tutorial 6: Data Manipulation Language
https://www.gcreddy.com/2017/06/sql-tutorial-6-data-manipulation.html
SQL Tutorial 7: SQL Operators
https://www.gcreddy.com/2017/06/sql-operators.html
SQL Tutorial 8: The Select Query
https://youtu.be/kid__0MNRps
SQL Tutorial 9: SQL Joins
https://youtu.be/K6U_WtYb-xQ
SQL Tutorial 10: SQL Functions
https://youtu.be/kgNnLWRZOiI
SQL Tutorial 11: SQL Comments
https://youtu.be/fg11vHRSsk0
SQL Tutorial 12: SQL Date Functions
https://youtu.be/EcanQwCjdWQ
Top 10 Database Management Systems
https://youtu.be/9R8xVrMgOb8
SQL vs. NoSQL Databases
https://youtu.be/1rX4yTqxdfQ
SQL Interview Questions and Answers
https://www.gcreddy.com/2013/01/sql-interview-questions.html
————————–