SlideShare a Scribd company logo
1 of 19
Download to read offline
Operator in SQL
Type of 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 comparisons and
arithmetic operations. These Operators are used to
specify conditions in an SQL statement and to serve as
conjunctions for multiple conditions in a statement.
• Arithmetic operators
• Comparison operators
• Logical operators
• Set Operators
Arithmetic Operators
• Arithmetic Operators
– Arithmetic operators are used to manipulate
numeric operands, which are columns Arithmetic
operators are used to manipulate numeric
operands, which are columns
• Types of arithmetic operators:
– Monadic Arithmetic Operators, which are namely,
• + and –
– Dyadic Arithmetic Operators, which are namely,
• /,*,+ and -
Rule:
If the value of any operand in a numeric value expression is null value, then
the result of thatnumeric value expression is the null value.
Arithmetic Operators
Operator Description Example
+ (Addition)
Adds values on either side
of the operator.
a + b will give 30
- (Subtraction)
Subtracts righthand
operand from left hand
operand.
a - b will give -10
* (Multiplication)
Multiplies values on either
side of the operator.
a * b will give 200
/ (Division)
Divides left hand operand
by right hand operand.
b / a will give 2
% (Modulus)
Divides left hand operand
by right hand operand and
returns remainder.
b % a will give 0
SQL Comparison Operators
• Assume 'variable a' holds 10 and 'variable b' holds 20, then
−
Operator Description Example
=
Checks if the values of two operands are equal or not, if yes then
condition becomes true.
(a = b) is not true.
!=
Checks if the values of two operands are equal or not, if values are
not equal then condition becomes true.
(a !=b) is true.
<>
Checks if the values of two operands are equal or not, if values are
not equal then condition becomes true.
(a <> b) is true.
>
Checks if the value of left operand is greater thanthe value of right
operand, if yes then condition becomes true.
(a > b) is not true.
<
Checks if the value of left operand is less than thevalue of right
operand, if yes then condition becomes true.
(a < b) is true.
>=
Checks if the value of left operand is greater thanor equal to the
value of right operand, if yes then condition becomes true.
(a >= b) is not true.
<=
Checks if the value of left operand is less than or equal to thevalue
of right operand, if yes then condition becomes true.
(a <= b) is true.
!<
Checks if the value of left operand is not less than thevalue of
right operand, if yes then condition becomes true.
(a !<b) is false.
!>
Checks if the value of left operand is not greater thanthe value of
right operand, if yes then condition becomes true.
(a !>b) is true
SQL Comparison Operators - Continues
• BETWEEN
The BETWEEN operator is used to search for values that are within a set of values, given the
minimum value and the maximum value.
• IN
The IN operator is used to compare a value to a list of literal values thathave been
specified.
• IS NULL
The NULL operator is used to compare a value with a NULL value.
• ALL
The ALL operator is used to compare a value to all values in another value set.
• ANY
The ANY operator is used to compare a value to anyapplicable value in the list as per the
condition.
• UNIQUE
The UNIQUE operator searches every row of a specified table for uniqueness (no
duplicates).
• EXISTS
The EXISTS operator is used to search for the presence of a row in a specified table that
meets a certain criterion.
Logical Operators
• AND
• The AND operatorallows the existenceof
multiple conditionsin an SQL statement's
WHERE clause
• NOT
• The NOT operatorreversesthemeaning
of the logical operatorwith which it is
used.Eg: NOT EXISTS,NOT BETWEEN,
NOT IN, etc. This is a negateoperator.
• OR
• The OR operatoris used to combine
multiple conditionsin an SQL statement's
WHERE clause.
Logical Operators
Set Operators
UNION -SYNTAX
UNION A U B
UNION - EXAMPLE
UNION ALL
INTERSECT
• The following statement combines the
results with the INTERSECT operator,
which returns only those rows returned by
both queries:
• SELECT empno FROM emp
INTERSECT
SELECT empno FROM oldemp;
INTERSECT - Example
MINUS
• The following statement combines results
with the MINUS operator, which returns
only rows returned by the first query but
not by the second:
• SELECT empno FROM emp
MINUS
SELECT empno FROM oldemp;
Minus - Example
• QUESTIONS?
SQL Operators: A Guide to Comparison, Arithmetic, Logical, and Set Operators

More Related Content

What's hot (20)

Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
Stack
StackStack
Stack
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Stack
StackStack
Stack
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
8. sql
8. sql8. sql
8. sql
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Subqueries
SubqueriesSubqueries
Subqueries
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Labels and buttons
Labels and buttonsLabels and buttons
Labels and buttons
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Лекция 1. Основы объектно-ориентированного программирования
Лекция 1. Основы объектно-ориентированного программированияЛекция 1. Основы объектно-ориентированного программирования
Лекция 1. Основы объектно-ориентированного программирования
 
Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
 
Access modifiers
Access modifiersAccess modifiers
Access modifiers
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
 
Unary operator overloading
Unary operator overloadingUnary operator overloading
Unary operator overloading
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 

Similar to SQL Operators: A Guide to Comparison, Arithmetic, Logical, and Set Operators

Similar to SQL Operators: A Guide to Comparison, Arithmetic, Logical, and Set Operators (20)

OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++
 
c# operators
c# operatorsc# operators
c# operators
 
Java script session 4
Java script session 4Java script session 4
Java script session 4
 
Logical Operators C/C++ language Programming
Logical Operators C/C++ language ProgrammingLogical Operators C/C++ language Programming
Logical Operators C/C++ language Programming
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
 
Operator 04 (js)
Operator 04 (js)Operator 04 (js)
Operator 04 (js)
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Operators & Casts
Operators & CastsOperators & Casts
Operators & Casts
 
Operators in c++
Operators in c++Operators in c++
Operators in c++
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
 
Relational and logical operators
Relational and logical operatorsRelational and logical operators
Relational and logical operators
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt
 
Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
C# operators
C# operatorsC# operators
C# operators
 

Recently uploaded

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Recently uploaded (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

SQL Operators: A Guide to Comparison, Arithmetic, Logical, and Set Operators

  • 2. Type of 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 comparisons and arithmetic operations. These Operators are used to specify conditions in an SQL statement and to serve as conjunctions for multiple conditions in a statement. • Arithmetic operators • Comparison operators • Logical operators • Set Operators
  • 3. Arithmetic Operators • Arithmetic Operators – Arithmetic operators are used to manipulate numeric operands, which are columns Arithmetic operators are used to manipulate numeric operands, which are columns • Types of arithmetic operators: – Monadic Arithmetic Operators, which are namely, • + and – – Dyadic Arithmetic Operators, which are namely, • /,*,+ and - Rule: If the value of any operand in a numeric value expression is null value, then the result of thatnumeric value expression is the null value.
  • 4. Arithmetic Operators Operator Description Example + (Addition) Adds values on either side of the operator. a + b will give 30 - (Subtraction) Subtracts righthand operand from left hand operand. a - b will give -10 * (Multiplication) Multiplies values on either side of the operator. a * b will give 200 / (Division) Divides left hand operand by right hand operand. b / a will give 2 % (Modulus) Divides left hand operand by right hand operand and returns remainder. b % a will give 0
  • 5. SQL Comparison Operators • Assume 'variable a' holds 10 and 'variable b' holds 20, then − Operator Description Example = Checks if the values of two operands are equal or not, if yes then condition becomes true. (a = b) is not true. != Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. (a !=b) is true. <> Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. (a <> b) is true. > Checks if the value of left operand is greater thanthe value of right operand, if yes then condition becomes true. (a > b) is not true. < Checks if the value of left operand is less than thevalue of right operand, if yes then condition becomes true. (a < b) is true. >= Checks if the value of left operand is greater thanor equal to the value of right operand, if yes then condition becomes true. (a >= b) is not true. <= Checks if the value of left operand is less than or equal to thevalue of right operand, if yes then condition becomes true. (a <= b) is true. !< Checks if the value of left operand is not less than thevalue of right operand, if yes then condition becomes true. (a !<b) is false. !> Checks if the value of left operand is not greater thanthe value of right operand, if yes then condition becomes true. (a !>b) is true
  • 6. SQL Comparison Operators - Continues • BETWEEN The BETWEEN operator is used to search for values that are within a set of values, given the minimum value and the maximum value. • IN The IN operator is used to compare a value to a list of literal values thathave been specified. • IS NULL The NULL operator is used to compare a value with a NULL value. • ALL The ALL operator is used to compare a value to all values in another value set. • ANY The ANY operator is used to compare a value to anyapplicable value in the list as per the condition. • UNIQUE The UNIQUE operator searches every row of a specified table for uniqueness (no duplicates). • EXISTS The EXISTS operator is used to search for the presence of a row in a specified table that meets a certain criterion.
  • 7. Logical Operators • AND • The AND operatorallows the existenceof multiple conditionsin an SQL statement's WHERE clause • NOT • The NOT operatorreversesthemeaning of the logical operatorwith which it is used.Eg: NOT EXISTS,NOT BETWEEN, NOT IN, etc. This is a negateoperator. • OR • The OR operatoris used to combine multiple conditionsin an SQL statement's WHERE clause.
  • 14. INTERSECT • The following statement combines the results with the INTERSECT operator, which returns only those rows returned by both queries: • SELECT empno FROM emp INTERSECT SELECT empno FROM oldemp;
  • 16. MINUS • The following statement combines results with the MINUS operator, which returns only rows returned by the first query but not by the second: • SELECT empno FROM emp MINUS SELECT empno FROM oldemp;