0% found this document useful (0 votes)
2 views31 pages

SQL Set Opeartion

The document provides an introduction to SQL and PL/SQL, detailing SQL's role in managing relational databases. It covers various set operations such as UNION, UNION ALL, INTERSECT, and MINUS, along with their syntax and examples. Additionally, it discusses comparison operators used in SQL for evaluating conditions between values.

Uploaded by

smitagade2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views31 pages

SQL Set Opeartion

The document provides an introduction to SQL and PL/SQL, detailing SQL's role in managing relational databases. It covers various set operations such as UNION, UNION ALL, INTERSECT, and MINUS, along with their syntax and examples. Additionally, it discusses comparison operators used in SQL for evaluating conditions between values.

Uploaded by

smitagade2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

DATABASE MANAGEMENT

SYSTEM
UNIT III
INTRODUCTION TO SQL - PL/SQL

Presented By:
Prof. N.S.Kazzi
SET OPERATION
 SQL stands for Structured Query Language.
 It is used for storing and managing data in

relational database management system


(RDMS).
 It is a standard language for Relational Database

System.
 It enables a user to create, read, update and

delete relational databases and tables.


 All the RDBMS like MySQL, Informix, Oracle, MS

Access and SQL Server use SQL as their standard


database language.
 SQL allows users to query the database in a

number of ways, using English-like statements.


SET OPERATION
 1. UNION:
 The SQL Union operation is used to combine the

result of two or more SQL SELECT queries.


 In the union operation, all the number of

datatype and columns must be same in both the


tables on which UNION operation is being
applied.
 The union operation eliminates the duplicate

rows from its resultset.


 Syntax

 SELECT column_name FROM table1

 UNION

 SELECT column_name FROM table2;


SET OPERATION
 1. UNION Example:
The First table
SET OPERATION
 1. UNION Example:
Union SQL query will be:
 SELECT * FROM First

 UNION

 SELECT * FROM Second;

 The resultset table will look like:


SET OPERATION
 2. Union All
 Union All operation is equal to the Union

operation. It returns the set without removing


duplication and sorting the data.
 Syntax:

 SELECT column_name FROM table1

 UNION ALL

 SELECT column_name FROM table2;


SET OPERATION
 2. Union All
 Example: Using the above First and Second

table.
Union All query will be like:
 SELECT * FROM First

 UNION ALL

 SELECT * FROM Second;


SET OPERATION
 2. Union All
 The resultset table will look like:
SET OPERATION
 3. Intersect
 It is used to combine two SELECT statements.

 The Intersect operation returns the common rows

from both the SELECT statements.


 In the Intersect operation, the number of
datatype and columns must be the same.
 It has no duplicates and it arranges the data in

ascending order by default.


SET OPERATION
 3. Intersect
Syntax:
 SELECT column_name FROM table1

 INTERSECT

 SELECT column_name FROM table2;

Example:
Using the above First and Second table.
Intersect query will be:
 SELECT * FROM First

 INTERSECT

 SELECT * FROM Second;


SET OPERATION
 3. Intersect
The resultset table will look like:
SET OPERATION
 4. Minus
 It combines the result of two SELECT statements.

Minus operator is used to display the rows which


are present in the first query but absent in the
second query.
 It has no duplicates and data arranged in

ascending order by default.


Syntax:
 SELECT column_name FROM table1

 MINUS

 SELECT column_name FROM table2;


SET OPERATION
 4. Minus
 Example

Using the above First and Second table.


Minus query will be:
 SELECT * FROM First

 MINUS

 SELECT * FROM Second;

 The resultset table will look like:


COMPARISON OPERATOR
 A comparison (or relational) operator is a
mathematical symbol which is used to compare
two values.
 Comparison operators are used in conditions that

compares one expression with another.


 The result of a comparison can be TRUE, FALSE,

or UNKNOWN.
COMPARISON OPERATOR
 The following table describes different types of
comparison operators -
COMPARISON OPERATOR
 Syntax :
 SELECT[column_name| * |

expression]<comparison operator>
[column_name | * | expression ] FROM
<table_name> WHERE
<expression>[comparison
operator]<expression>;
COMPARISON OPERATOR
 Parameters:
COMPARISON OPERATOR
 Example: SQL Comparison operator
 To get a comparison between two numbers from

the DUAL table, the following SQL statement can


be used :
 SELECT 15>14 FROM dual;
COMPARISON OPERATOR
 Example: SQL Comparison operator
 SELECT * FROM MATHS;
COMPARISON OPERATOR
 Demonstration of various Comparison
Operators in SQL:
 Equal to (=) Operator: It returns the
rows/tuples which have the value of the attribute
equal to the given value.
 Query:

 SELECT * FROM MATHS WHERE MARKS=50;


COMPARISON OPERATOR
 Equal to (=) Operator:
COMPARISON OPERATOR
 Greater than (>) Operator: It returns the
rows/tuples which have the value of the attribute
greater than the given value.
 Query:

 SELECT * FROM MATHS WHERE MARKS>60;


COMPARISON OPERATOR
 Greater than (>) Operator:
COMPARISON OPERATOR
 Less than (<) Operator: It returns the
rows/tuples which have the value of the attribute
lesser than the given value.
 Query:

 SELECT * FROM MATHS WHERE MARKS<40;


COMPARISON OPERATOR
 Less than (<) Operator:
COMPARISON OPERATOR
 Greater than or equal to (>=) Operator: It
returns the rows/tuples which have the value of
the attribute greater or equal to the given value.
 Query:

 SELECT * FROM MATHS WHERE MARKS>=80;


COMPARISON OPERATOR
 Greater than or equal to (>=) Operator:
COMPARISON OPERATOR
 Less than or equal to (<=) Operator: It
returns the rows/tuples which have the value of
the attribute lesser or equal to the given value.
 Query:

 SELECT * FROM MATHS WHERE MARKS<=30;


COMPARISON OPERATOR
 Less than or equal to (<=) Operator:
COMPARISON OPERATOR
 Not equal to (<>) Operator: It returns the
rows/tuples which have the value of the attribute
not equal to the given value.
 Query:

 SELECT * FROM MATHS WHERE MARKS<>70;


COMPARISON OPERATOR
 Not equal to (<>) Operator:

You might also like