1
PostgreSQL Operators
2
• SQL operators are reserved keywords used in the WHERE clause of a SQL
statement to perform arithmetic, logical and comparison operations.
• Operators act as conjunctions in SQL statements to fulfill multiple conditions
in a statement.
What are SQL operators?
3
• While handling data in databases, we often tend to perform different kinds of
operations to manipulate and retrieve data.
• SQL being the base of database management systems, offers various operators
to perform such operations.
• The various operators used in SQL, in the following sequence:
• Types of Operators:
1) Arithmetic Operators
2) Comparison Operators
3) Logical Operators
What are SQL Operators and how do they work?
4
• These operators are used to perform operations such as addition, multiplication, subtraction etc.
Example:
• SELECT 40 + 20;
• SELECT 40 - 20;
• SELECT 40 * 20;
• SELECT 40 / 20;
• SELECT 40 % 20;
1. Arithmetic Operators
Operator Operation Description
+ Addition Add values on either side of the operator
– Subtraction Used to subtract the right hand side value from the left hand side value
* Multiplication Multiples the values present on each side of the operator
/ Division Divides the left hand side value by the right hand side value
% Modulus
Divides the left hand side value by the right hand side value; and returns the
remainder
5
• These operators are used to perform operations such as equal to, greater than,
less than etc.
2. Comparison Operators
Operator Operation Description
= Equal to Used to check if the values of both operands are equal or not. If they are equal, then it returns TRUE.
> Greater than Returns TRUE if the value of left operand is greater than the right operand.
< Less than Checks whether the value of left operand is less than the right operand, if yes returns TRUE.
>=
Greater than or
equal to
Used to check if the left operand is greater than or equal to the right operand, and returns TRUE, if the
condition is true.
<=
Less than or equal
to
Returns TRUE if the left operand is less than or equal to the right operand.
<> or != Not equal to Used to check if values of operands are equal or not. If they are not equal then, it returns TRUE.
!> Not greater than Checks whether the left operand is not greater than the right operand, if yes then returns TRUE.
!< Not less than Returns TRUE, if the left operand is not less than the right operand.
6
• For better understanding, the following table to perform various operations.
• Example[Use equal to]:
SELECT * FROM Students
WHERE Age = 20;
• Output:
2. Comparison Operators : Example
StudentID FirstName LastName Age
1 Atul Mishra 23
2 Priya Kapoor 21
3 Rohan Singhania 21
4 Akanksha Jain 20
5 Vaibhav Gupta 25
StudentID FirstName LastName Age
4 Akanksha Jain 20
7
• The logical operators are used to perform operations such as ALL, ANY, NOT,
BETWEEN etc.
3. Logical Operators
Operator Description
ALL Used to compare a specific value to all other values in a set
ANY Compares a specific value to any of the values present in a set.
IN Used to compare a specific value to the literal values mentioned.
BETWEEN Searches for values within the range mentioned.
AND Allows the user to mention multiple conditions in a WHERE clause.
OR Combines multiple conditions in a WHERE clause.
NOT A negate operators, used to reverse the output of the logical operator.
EXISTS Used to search for the row’s presence in the table.
LIKE Compares a pattern using wildcard operators.
SOME Similar to the ANY operator, and is used compares a specific value to some of the values present in a set.
3. Logical Operators : Examples
8
SELECT * FROM Students WHERE Age > ANY (SELECT Age FROM Students WHERE Age > 21);
StudentID FirstName LastName Age
1 Atul Mishra 23
5 Vaibhav Gupta 25
Example[ANY]
Output:
9
3. Logical Operators : Examples
SELECT * FROM Students WHERE Age BETWEEN 22 AND 25;
StudentID FirstName LastName Age
1 Atul Mishra 23
Example[BETWEEN & AND]
Output:
10
3. Logical Operators : Examples
SELECT * FROM Students WHERE Age IN('23', '20');
StudentID FirstName LastName Age
1 Atul Mishra 23
4 Akanksha Jain 20
Example[IN]
Output:
11
• When you query data from a table, PostgreSQL returns the rows in an unspecified order.
• To sort the result set, you use the ORDER BY clause in the SELECT statement.
• The ORDER BY clause allows you to sort rows returned from a SELECT statement in
ascending or descending order based on the specified criteria.
• The following illustrates the syntax of the ORDER BY clause:
4. ORDER BY clause
SELECT
column_1,
column_2
FROM
table_name
ORDER BY
column_1 [ASC | DESC],
column_2 [ASC | DESC];
12
• In this syntax:
• First, specify a column or an expression that you want to sort in the ORDER BY clause.
• If you sort the result set based on multiple columns or expressions, you use a comma to separate two
columns or expressions.
• Second, use ASC to sort the result set in ascending order and DESCto sort the result set in
descending order.
• If skip the ASC or DESC option, the ORDER BY uses ASC by default.
• Example : SELECT * FROM COMPANY ORDER BY AGE ASC;
4. ORDER BY clause

More Related Content

PPTX
SQL Operators.pptx
PDF
SQL Operator.pdf
PPTX
Sql operator
PPTX
SQL Operators.pptx
PPT
Chapter-4.ppt
PDF
Logic operators [Slides].pdf introductory
PDF
Sq lite expressions
PDF
SQL Lesson 6 - Select.pdf
SQL Operators.pptx
SQL Operator.pdf
Sql operator
SQL Operators.pptx
Chapter-4.ppt
Logic operators [Slides].pdf introductory
Sq lite expressions
SQL Lesson 6 - Select.pdf

Similar to PostgreSQL (PostgreSQL is a versatile, open-source object-relational database system) Mathematical Operators.pptx (20)

PDF
Structured Query Language (SQL) - An Introduction
PPTX
OPerators.pptx Best topics dbms. Good one
PPTX
Structure Query Language (SQL).pptx
PPTX
Dbms presentationnnnn
PPT
PPTX
ADVANCE ITT BY PRASAD
DOC
Sql functions
PDF
Sql operators comparision & logical operators
PPT
asdasdasdasdsadasdasdasdasdsadasdasdasdsadsadasd
PPTX
SQL Course - QA
PDF
advance-sqaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal.pdf
PPT
Chinabankppt
PPTX
Data Manipulation Language.pptx
PPTX
literals operators datatypes and its adv
PPTX
Structure query language (sql)
PDF
Data Base Management System Lecture 10.pdf
PPTX
PDF
Basics of SELECT Statement - Oracle SQL
PPTX
SQL(NEW).pptx
PPTX
DDL and DML statements.pptx
Structured Query Language (SQL) - An Introduction
OPerators.pptx Best topics dbms. Good one
Structure Query Language (SQL).pptx
Dbms presentationnnnn
ADVANCE ITT BY PRASAD
Sql functions
Sql operators comparision & logical operators
asdasdasdasdsadasdasdasdasdsadasdasdasdsadsadasd
SQL Course - QA
advance-sqaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal.pdf
Chinabankppt
Data Manipulation Language.pptx
literals operators datatypes and its adv
Structure query language (sql)
Data Base Management System Lecture 10.pdf
Basics of SELECT Statement - Oracle SQL
SQL(NEW).pptx
DDL and DML statements.pptx
Ad

More from BINJAD1 (20)

PPTX
Joins (A JOIN clause is used to combine rows from two or more tables, based o...
PPTX
3D-Object Representation in Computer Graphics.pptx
PPTX
Visible Surface Detection Methods in Computer Graphics.pptx
PDF
Number Systems (These are ways of representing numbers using symbols and rule...
PDF
Computer Logical Organization(It refers to how its functional units are arran...
PDF
Logic Gates(Logic gates are fundamental building blocks of digital circuits).pdf
PDF
Digital Concepts (Digital electronics is a branch of electronics).pdf
PDF
sequential logic circuits- Latch & Flip Flop.pdf
PDF
Object Oriented Programming with Java Basic Syntax.pdf
PDF
AWT (Abstract Window Toolkit) Controls.pdf
PDF
Introduction to Microsoft Access (MS Access).pdf
PPTX
Database Administration (Database Administrator (DBA) is a professional respo...
PPTX
Database Administration (Database Administrator (DBA) is a professional respo...
PPTX
Database (DB- A database is an electronically stored, systematic collection o...
PPTX
Pixel- A pixel, short for "picture element.pptx
PPT
Introduction to Computer Graphics or CG.ppt
PPT
2D-Transformations-Transformations are the operations applied to geometrical ...
PPTX
2D Viewing- the window by setting a two-dimensional viewing co-ordinate syst...
PPTX
The internet and WWW-he terms World Wide Web (WWW) and the Internet
PPTX
Structured Query Language (SQL)- standard Database language
Joins (A JOIN clause is used to combine rows from two or more tables, based o...
3D-Object Representation in Computer Graphics.pptx
Visible Surface Detection Methods in Computer Graphics.pptx
Number Systems (These are ways of representing numbers using symbols and rule...
Computer Logical Organization(It refers to how its functional units are arran...
Logic Gates(Logic gates are fundamental building blocks of digital circuits).pdf
Digital Concepts (Digital electronics is a branch of electronics).pdf
sequential logic circuits- Latch & Flip Flop.pdf
Object Oriented Programming with Java Basic Syntax.pdf
AWT (Abstract Window Toolkit) Controls.pdf
Introduction to Microsoft Access (MS Access).pdf
Database Administration (Database Administrator (DBA) is a professional respo...
Database Administration (Database Administrator (DBA) is a professional respo...
Database (DB- A database is an electronically stored, systematic collection o...
Pixel- A pixel, short for "picture element.pptx
Introduction to Computer Graphics or CG.ppt
2D-Transformations-Transformations are the operations applied to geometrical ...
2D Viewing- the window by setting a two-dimensional viewing co-ordinate syst...
The internet and WWW-he terms World Wide Web (WWW) and the Internet
Structured Query Language (SQL)- standard Database language
Ad

Recently uploaded (20)

PPTX
Build Your First AI Agent with UiPath.pptx
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
Five Habits of High-Impact Board Members
PDF
A proposed approach for plagiarism detection in Myanmar Unicode text
PDF
sbt 2.0: go big (Scala Days 2025 edition)
PPTX
Training Program for knowledge in solar cell and solar industry
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PDF
Getting started with AI Agents and Multi-Agent Systems
PPTX
Microsoft Excel 365/2024 Beginner's training
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
Module 1 Introduction to Web Programming .pptx
PDF
CloudStack 4.21: First Look Webinar slides
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
DOCX
Basics of Cloud Computing - Cloud Ecosystem
PPTX
TEXTILE technology diploma scope and career opportunities
PPT
What is a Computer? Input Devices /output devices
PDF
Architecture types and enterprise applications.pdf
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
Build Your First AI Agent with UiPath.pptx
Custom Battery Pack Design Considerations for Performance and Safety
Module 1.ppt Iot fundamentals and Architecture
Five Habits of High-Impact Board Members
A proposed approach for plagiarism detection in Myanmar Unicode text
sbt 2.0: go big (Scala Days 2025 edition)
Training Program for knowledge in solar cell and solar industry
Convolutional neural network based encoder-decoder for efficient real-time ob...
Getting started with AI Agents and Multi-Agent Systems
Microsoft Excel 365/2024 Beginner's training
Final SEM Unit 1 for mit wpu at pune .pptx
Module 1 Introduction to Web Programming .pptx
CloudStack 4.21: First Look Webinar slides
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Basics of Cloud Computing - Cloud Ecosystem
TEXTILE technology diploma scope and career opportunities
What is a Computer? Input Devices /output devices
Architecture types and enterprise applications.pdf
OpenACC and Open Hackathons Monthly Highlights July 2025
A contest of sentiment analysis: k-nearest neighbor versus neural network

PostgreSQL (PostgreSQL is a versatile, open-source object-relational database system) Mathematical Operators.pptx

  • 2. 2 • SQL operators are reserved keywords used in the WHERE clause of a SQL statement to perform arithmetic, logical and comparison operations. • Operators act as conjunctions in SQL statements to fulfill multiple conditions in a statement. What are SQL operators?
  • 3. 3 • While handling data in databases, we often tend to perform different kinds of operations to manipulate and retrieve data. • SQL being the base of database management systems, offers various operators to perform such operations. • The various operators used in SQL, in the following sequence: • Types of Operators: 1) Arithmetic Operators 2) Comparison Operators 3) Logical Operators What are SQL Operators and how do they work?
  • 4. 4 • These operators are used to perform operations such as addition, multiplication, subtraction etc. Example: • SELECT 40 + 20; • SELECT 40 - 20; • SELECT 40 * 20; • SELECT 40 / 20; • SELECT 40 % 20; 1. Arithmetic Operators Operator Operation Description + Addition Add values on either side of the operator – Subtraction Used to subtract the right hand side value from the left hand side value * Multiplication Multiples the values present on each side of the operator / Division Divides the left hand side value by the right hand side value % Modulus Divides the left hand side value by the right hand side value; and returns the remainder
  • 5. 5 • These operators are used to perform operations such as equal to, greater than, less than etc. 2. Comparison Operators Operator Operation Description = Equal to Used to check if the values of both operands are equal or not. If they are equal, then it returns TRUE. > Greater than Returns TRUE if the value of left operand is greater than the right operand. < Less than Checks whether the value of left operand is less than the right operand, if yes returns TRUE. >= Greater than or equal to Used to check if the left operand is greater than or equal to the right operand, and returns TRUE, if the condition is true. <= Less than or equal to Returns TRUE if the left operand is less than or equal to the right operand. <> or != Not equal to Used to check if values of operands are equal or not. If they are not equal then, it returns TRUE. !> Not greater than Checks whether the left operand is not greater than the right operand, if yes then returns TRUE. !< Not less than Returns TRUE, if the left operand is not less than the right operand.
  • 6. 6 • For better understanding, the following table to perform various operations. • Example[Use equal to]: SELECT * FROM Students WHERE Age = 20; • Output: 2. Comparison Operators : Example StudentID FirstName LastName Age 1 Atul Mishra 23 2 Priya Kapoor 21 3 Rohan Singhania 21 4 Akanksha Jain 20 5 Vaibhav Gupta 25 StudentID FirstName LastName Age 4 Akanksha Jain 20
  • 7. 7 • The logical operators are used to perform operations such as ALL, ANY, NOT, BETWEEN etc. 3. Logical Operators Operator Description ALL Used to compare a specific value to all other values in a set ANY Compares a specific value to any of the values present in a set. IN Used to compare a specific value to the literal values mentioned. BETWEEN Searches for values within the range mentioned. AND Allows the user to mention multiple conditions in a WHERE clause. OR Combines multiple conditions in a WHERE clause. NOT A negate operators, used to reverse the output of the logical operator. EXISTS Used to search for the row’s presence in the table. LIKE Compares a pattern using wildcard operators. SOME Similar to the ANY operator, and is used compares a specific value to some of the values present in a set.
  • 8. 3. Logical Operators : Examples 8 SELECT * FROM Students WHERE Age > ANY (SELECT Age FROM Students WHERE Age > 21); StudentID FirstName LastName Age 1 Atul Mishra 23 5 Vaibhav Gupta 25 Example[ANY] Output:
  • 9. 9 3. Logical Operators : Examples SELECT * FROM Students WHERE Age BETWEEN 22 AND 25; StudentID FirstName LastName Age 1 Atul Mishra 23 Example[BETWEEN & AND] Output:
  • 10. 10 3. Logical Operators : Examples SELECT * FROM Students WHERE Age IN('23', '20'); StudentID FirstName LastName Age 1 Atul Mishra 23 4 Akanksha Jain 20 Example[IN] Output:
  • 11. 11 • When you query data from a table, PostgreSQL returns the rows in an unspecified order. • To sort the result set, you use the ORDER BY clause in the SELECT statement. • The ORDER BY clause allows you to sort rows returned from a SELECT statement in ascending or descending order based on the specified criteria. • The following illustrates the syntax of the ORDER BY clause: 4. ORDER BY clause SELECT column_1, column_2 FROM table_name ORDER BY column_1 [ASC | DESC], column_2 [ASC | DESC];
  • 12. 12 • In this syntax: • First, specify a column or an expression that you want to sort in the ORDER BY clause. • If you sort the result set based on multiple columns or expressions, you use a comma to separate two columns or expressions. • Second, use ASC to sort the result set in ascending order and DESCto sort the result set in descending order. • If skip the ASC or DESC option, the ORDER BY uses ASC by default. • Example : SELECT * FROM COMPANY ORDER BY AGE ASC; 4. ORDER BY clause