SlideShare a Scribd company logo
Relational Algebra in DBMS
Relational Algebra
• Relational algebra in DBMS is a procedural query language.
• Queries in relational algebra are performed
using operators. An operator can be either unary or binary.
• Relational Algebra is a procedural query language.
Relational algebra mainly provides a theoretical foundation
for relational databases and SQL.
• The main purpose of using Relational Algebra is to define
operators that transform one or more input relations into
an output relation.
• Relational Algebra came in 1970 and was given by Edgar F.
Codd (Father of DBMS). It is also known as Procedural
Query Language(PQL) as in PQL, a programmer/user has to
mention two things, "What to Do" and "How to Do".
Relational Operations in DBMS
• Relational algebra is a procedural query language.
It gives a step by step process to obtain the result
of the query.
• In Relational Algebra, we have two types of
Operations.
• Basic Operations
• Derived Operations
• Applying these operations over relations/tables
will give us new relations as output.
Relational Algebra in DBMS power ppoint pesenetation
Select Operation (σ)
• Select (σ)
• Select operation is done by Selection Operator which is represented
by "sigma"(σ). It is used to retrieve tuples(rows) from the table where the
given condition is satisfied. It is a unary operator means it requires only
one operand.
• Notation : σ p(R)
• Where σ is used to represent SELECTION
• R is used to represent RELATION
• p is the logic formula
• Example: σ AGE=20 (STUDENT)
Types of Relational operation
Select Operation (σ)
• where σ stands for selecting tuples (rows) and r stands for
relation (table) name. p is prepositional logic formula which
may use connectors like and, or, and not. These terms may use
relational operators like = , ≠ , ≥ , < , > , ≤ .
• Example 1: σsubject = "database"(Books)
• Output : Selects rows whose subject is 'database' from books
table.
• Example 2: σ subject = "database" and price = "450"(Books)
• Output : Selects rows from books where subject is 'database'
and 'price' is 450.
• Example 3: σ subject = "database" and price = "450" or year
> "2010"(Books)
• Output : Selects rows from books where subject is 'database'
and 'price' is 450 or those books published after 2010.
Project Operation (∏)
• Project (∏)
• Project operation is done by Projection Operator which is
represented by "pi"(∏).
• It is used to retrieve certain attributes(columns) from the
table.
• It is also known as vertical partitioning as it separates the
table vertically. It is also a unary operator.
• Notation: ∏ A1, A2, … An (R)
• where A1, A2 , An are column (attribute) names of relation R.
• Duplicate rows are automatically eliminated in the output.
• Example: ∏ subject, author (Books)
• Display values from columns subject and author from the
relation Books.
Union Operation ( )
∪
• Union ( )
∪
• Union operation is done by Union Operator which is
represented by "union"( ).
∪
• It is the same as the union operator from set theory, i.e., it
selects all tuples from both relations but with the exception
that for the union of two relations/tables both relations must
have the same set of Attributes.
• It is a binary operator as it requires two operands.
Notation: R S
∪
Where R is the first relation
S is the second relation
• If relations don't have the same set of attributes, then the union of such
relations will result in NULL.
• ∏ NAME(STUDENT) ∏
∪ NAME(EMPLOYEE)
Intersection Operation (∩)
• Intersection (∩)
• Intersection operation is done by Intersection Operator which is
represented by "intersection"(∩).
• It is the same as the intersection operator from set theory, i.e., it selects
all the tuples which are present in both relations.
• It is a binary operator as it requires two operands. Also, it eliminates
duplicates.
Notation : R ∩ S
Where R is the first relation
S is the second relation
• Example : we want the names which are present in STUDENT as well as
in EMPLOYEE relation, Relations we used in Basic Operations.
• ∏ NAME(STUDENT) ∩ ∏ NAME(EMPLOYEE)
Set Difference (−)
• Set Difference (-)
• Set Difference as its name indicates is the difference
between two relations (R-S).
• It is denoted by a "Hyphen"(-) and it returns all the
tuples(rows) which are in relation R but not in relation S.
• It is also a binary operator.
Notation : R - S
Where R is the first relation
S is the second relation
• Just like union, the set difference also comes with the
exception of the same set of attributes in both relations.
Cartesian Product (Χ):
• Cartesian product (X)
• Cartesian product is denoted by the "X" symbol.
• we have two relations R and S. Cartesian product will combine
every tuple(row) from R with all the tuples from S.
• It is also a binary operator.
•
Notation: R X S
Where R is the first relation
S is the second relation
• Example: Π author (Books) X Π author (Articles)
Rename Operation (ρ)
• Rename (ρ)
• Rename operation is denoted by "Rho"(ρ).
• As its name suggests it is used to rename the output relation.
Rename operator too is a binary operator.
• Notation: ρ(R,S)
Where R is the new relation name
S is the old relation name
• we are fetching the names of students from STUDENT relation.
We would like to rename this relation as STUDENT_NAME.
• ρ(STUDENT_NAME,∏ NAME(STUDENT))
Overview
• Select (σ) is used to retrieve tuples(rows) based on certain
conditions.
• Project (∏) is used to retrieve attributes(columns) from the
relation.
• Union ( )
∪ is used to retrieve all the tuples from two
relations.
• Set Difference (-) is used to retrieve the tuples which are
present in R but not in S(R-S).
• Cartesian product (X) is used to combine each tuple from the
first relation with each tuple from the second relation.
• Rename (ρ) is used to rename the output relation.
Division (/):
• Division (÷)
• Division Operation is represented by "division"(÷
or /) operator and is used in queries that involve
keywords "every", "all", etc.
Notation : R(X,Y)/S(Y)
Here,
R is the first relation from which data is retrieved.
S is the second relation that will help to retrieve the
data.
• X and Y are the attributes/columns present in relation. We can have
multiple attributes in relation, but keep in mind that attributes of S must
be a proper subset of attributes of R.
• For each corresponding value of Y, the above notation will return us the
value of X from tuple<X,Y> which exists everywhere.
• It's a bit difficult to understand this in a theoretical way, but you will
understand this with an example.
• Let's have two relations, ENROLLED and COURSE. ENROLLED consist of
two attributes STUDENT_ID and COURSE_ID. It denotes the map of
students who are enrolled in given courses.
• COURSE contains the list of courses available.
• ENROLLED(STUDENT_ID, COURSE_ID)/COURSE(COURSE_ID)
SQL JOINS
• SQL Join statement is used to combine data or
rows from two or more tables based on a common
field between them. Different types of Joins are as
follows:
• INNER JOIN
• LEFT JOIN
• RIGHT JOIN
• FULL JOIN
• NATURAL JOIN
SQL JOINS
• JOIN is an SQL clause used to query and
access data from multiple tables, based on
logical relationships between those tables.
INNER JOIN
• A. INNER JOIN
• The INNER JOIN keyword selects all rows from both the tables as long as the
condition is satisfied. This keyword will create the result-set by combining all
rows from both the tables where the condition satisfies i.e value of the common
field will be the same.
• SELECT table1.column1,table1.column2,table2.column1,....
FROM table1
INNER JOIN table2
ON table1.matching_column = table2.matching_column;
table1: First table.
table2: Second table
matching_column: Column common to both the tables.
INNER JOIN
• Example Queries(INNER JOIN)
• This query will show the names and age of students enrolled in different
courses.
• SELECT StudentCourse.COURSE_ID, Student.NAME, Student.AGE FROM
Student
INNER JOIN StudentCourse
ON Student.ROLL_NO = StudentCourse.ROLL_NO;
LEFT JOIN
• B. LEFT JOIN
• This join returns all the rows of the table on the left side of the join
and matches rows for the table on the right side of the join. For the
rows for which there is no matching row on the right side, the result-
set will contain null. LEFT JOIN is also known as LEFT OUTER JOIN.
• Syntax:
• SELECT table1.column1,table1.column2,table2.column1,....
FROM table1
LEFT JOIN table2
ON table1.matching_column = table2.matching_column;
table1: First table.
table2: Second table
matching_column: Column common to both the tables.
• Example Queries(LEFT JOIN):
• SELECT Student.NAME,StudentCourse.COURSE_ID
FROM Student
LEFT JOIN StudentCourse
ON StudentCourse.ROLL_NO = Student.ROLL_NO;
Output:
LEFT JOIN
RIGHT JOIN
• RIGHT JOIN
• RIGHT JOIN is similar to LEFT JOIN. This join returns all the rows of the table on
the right side of the join and matching rows for the table on the left side of the
join. For the rows for which there is no matching row on the left side, the result-
set will contain null. RIGHT JOIN is also known as RIGHT OUTER JOIN.
• Syntax:
• SELECT table1.column1,table1.column2,table2.column1,....
FROM table1
RIGHT JOIN table2
ON table1.matching_column = table2.matching_column;
table1: First table.
table2: Second table
matching_column: Column common to both the tables.
• Example Queries(RIGHT JOIN):
• SELECT Student.NAME,StudentCourse.COURSE_ID
FROM Student
RIGHT JOIN StudentCourse
ON StudentCourse.ROLL_NO = Student.ROLL_NO;
Output:
FULL JOIN
• FULL JOIN
• FULL JOIN creates the result-set by combining results of both
LEFT JOIN and RIGHT JOIN. The result-set will contain all the
rows from both tables. For the rows for which there is no
matching, the result-set will contain NULL values.
FULL JOIN
• Syntax:
• SELECT
table1.column1,table1.column2,table2.column1,....
FROM table1
FULL JOIN table2
ON table1.matching_column = table2.matching_column;
table1: First table.
table2: Second table
matching_column: Column common to both the tables.
FULL JOIN
• Example Queries(FULL JOIN):
• SELECT Student.NAME,StudentCourse.COURSE_ID
FROM Student
FULL JOIN StudentCourse
ON StudentCourse.ROLL_NO = Student.ROLL_NO;
Output:
NAME COURSE_I
D
HARSH 1
PRATIK 2
RIYANKA 2
DEEP 3
SAPTARHI 1
DHANRAJ NULL
ROHIT NULL
NIRAJ NULL
NULL 4
NULL 5
NULL 4
Natural join
• E. Natural join (?)
• Natural join can join tables based on the common
columns in the tables being joined. A natural join returns
all rows by matching values in common columns having
same name and data type of columns and that column
should be present in both tables.
• Both table must have at list one common column with
same column name and same data type.
• The two table are joined using Cross join.
• DBMS will look for a common column with same name
and data type Tuples having exactly same values in
common columns are kept in result.
Natural join
Employee
Emp_id Emp_name Dept_id
1 Ram 10
2 Jon 30
3 Bob 50
Department
Dept_id Dept_name
10 IT
30 HR
40 TIS
Query: Find all Employees and their respective
departments.
Solution: (Employee) ? (Department)
Emp_id Emp_name Dept_id Dept_id Dept_name
1 Ram 10 10 IT
2 Jon 30 30 HR
Employee data Department data
Example:

More Related Content

PDF
Unit-II DBMS presentation for students.pdf
ajajkhan16
 
PDF
1695304562_RELATIONAL_ALGEBRA.pdf
Kavinilaa
 
PDF
Relational model
SarithaDhanapal
 
PPTX
Relational Database management Systems unit-II
vanithar32
 
PPT
Ch7
muteddy
 
PPTX
Datqbase management system: Relational Algebra.pptx
ShubhamTiwari907077
 
PDF
Relational Algebra-23-04-2023.pdf
VADAPALLYPRAVEENKUMA1
 
PPTX
lecture 4 Relational Algebra my sql work
wwcd090
 
Unit-II DBMS presentation for students.pdf
ajajkhan16
 
1695304562_RELATIONAL_ALGEBRA.pdf
Kavinilaa
 
Relational model
SarithaDhanapal
 
Relational Database management Systems unit-II
vanithar32
 
Ch7
muteddy
 
Datqbase management system: Relational Algebra.pptx
ShubhamTiwari907077
 
Relational Algebra-23-04-2023.pdf
VADAPALLYPRAVEENKUMA1
 
lecture 4 Relational Algebra my sql work
wwcd090
 

Similar to Relational Algebra in DBMS power ppoint pesenetation (20)

PDF
IT-243-L13-14-1. pdf
NasirAli233814
 
PPTX
Relational Model,relational calulus.pptx
prachi gat
 
PPT
chapter 5-Relational Algebra and calculus.ppt
University of Gondar
 
PPTX
REC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptx
Uma Kakarlapudi
 
PPTX
Lect - 12 solve d.pptx
SumeetRathi5
 
PDF
Cs501 rel algebra
Kamal Singh Lodhi
 
PPT
Unit2 -DBMS.ppt with type of job operation
shindhe1098cv
 
PPTX
316_16SCCCS4_2020052505222431.pptdatabasex
abhaysonone0
 
PPTX
5th chapter Relational algebra.pptx
kavitha623544
 
DOCX
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Raj vardhan
 
PPT
354 ch6
Yibelital Alemu
 
PPTX
Chapter-6 Relational Algebra
Kunal Anand
 
PDF
ML111 Lecture 5 Relational Algebra and Advanced SQL.pdf
tory10027
 
PDF
Relational algebra complete
Visakh V
 
PDF
Chapter – 5 Relational Algebra.pdf
TamiratDejene1
 
PPTX
Relational algebr
Visakh V
 
PPT
Relational algebra operations
SanthiNivas
 
PPTX
DBMS - Relational Algebra
MythiliMurugan3
 
PPTX
Practice on Practical SQL
Hideshi Ogoshi
 
PPTX
advanced database management system by uni
VaibhavSrivastav52
 
IT-243-L13-14-1. pdf
NasirAli233814
 
Relational Model,relational calulus.pptx
prachi gat
 
chapter 5-Relational Algebra and calculus.ppt
University of Gondar
 
REC-UNIT-2-DATABASEMANAGEMENTSYSTEMS.pptx
Uma Kakarlapudi
 
Lect - 12 solve d.pptx
SumeetRathi5
 
Cs501 rel algebra
Kamal Singh Lodhi
 
Unit2 -DBMS.ppt with type of job operation
shindhe1098cv
 
316_16SCCCS4_2020052505222431.pptdatabasex
abhaysonone0
 
5th chapter Relational algebra.pptx
kavitha623544
 
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Raj vardhan
 
Chapter-6 Relational Algebra
Kunal Anand
 
ML111 Lecture 5 Relational Algebra and Advanced SQL.pdf
tory10027
 
Relational algebra complete
Visakh V
 
Chapter – 5 Relational Algebra.pdf
TamiratDejene1
 
Relational algebr
Visakh V
 
Relational algebra operations
SanthiNivas
 
DBMS - Relational Algebra
MythiliMurugan3
 
Practice on Practical SQL
Hideshi Ogoshi
 
advanced database management system by uni
VaibhavSrivastav52
 
Ad

More from AshokRachapalli1 (20)

PPT
215-Database-Recovery presentation document
AshokRachapalli1
 
PPTX
transactionprocessing-220423112118 (1).pptx
AshokRachapalli1
 
PPTX
unit-1 lecture 7 Types of system calls.pptx
AshokRachapalli1
 
PPTX
DATA MODEL Power point presentation for dbms
AshokRachapalli1
 
PPTX
WEEK-2 DML and operators power point presentation
AshokRachapalli1
 
PPTX
Relational Algebra in DBMS 2025 power point
AshokRachapalli1
 
PPTX
CLOSURE OF AN ATTRIBUTE powerpontpresentatio
AshokRachapalli1
 
PPT
Relational algebra in database management system
AshokRachapalli1
 
PPT
DBMS-3.1 Normalization upto boyscodd normal form
AshokRachapalli1
 
PPTX
Data base Users and Administrator pptx
AshokRachapalli1
 
PPTX
Database Languages power point presentation
AshokRachapalli1
 
PPTX
using Java Exception Handling in Java.pptx
AshokRachapalli1
 
PPTX
Multi-Threading in Java power point presenetation
AshokRachapalli1
 
PPT
ARRAYS in java with in details presentation.ppt
AshokRachapalli1
 
PPT
lecture-a-java-review .. this review ppt will help to the lectureres
AshokRachapalli1
 
PPTX
17.INTRODUCTION TO SCHEMA REFINEMENT.pptx
AshokRachapalli1
 
PPTX
joins in dbms its describes about how joins are important and necessity in d...
AshokRachapalli1
 
PPTX
6.Database Languages lab-1.pptx
AshokRachapalli1
 
PPT
Chapter5 (1).ppt
AshokRachapalli1
 
PPTX
Cache Memory.pptx
AshokRachapalli1
 
215-Database-Recovery presentation document
AshokRachapalli1
 
transactionprocessing-220423112118 (1).pptx
AshokRachapalli1
 
unit-1 lecture 7 Types of system calls.pptx
AshokRachapalli1
 
DATA MODEL Power point presentation for dbms
AshokRachapalli1
 
WEEK-2 DML and operators power point presentation
AshokRachapalli1
 
Relational Algebra in DBMS 2025 power point
AshokRachapalli1
 
CLOSURE OF AN ATTRIBUTE powerpontpresentatio
AshokRachapalli1
 
Relational algebra in database management system
AshokRachapalli1
 
DBMS-3.1 Normalization upto boyscodd normal form
AshokRachapalli1
 
Data base Users and Administrator pptx
AshokRachapalli1
 
Database Languages power point presentation
AshokRachapalli1
 
using Java Exception Handling in Java.pptx
AshokRachapalli1
 
Multi-Threading in Java power point presenetation
AshokRachapalli1
 
ARRAYS in java with in details presentation.ppt
AshokRachapalli1
 
lecture-a-java-review .. this review ppt will help to the lectureres
AshokRachapalli1
 
17.INTRODUCTION TO SCHEMA REFINEMENT.pptx
AshokRachapalli1
 
joins in dbms its describes about how joins are important and necessity in d...
AshokRachapalli1
 
6.Database Languages lab-1.pptx
AshokRachapalli1
 
Chapter5 (1).ppt
AshokRachapalli1
 
Cache Memory.pptx
AshokRachapalli1
 
Ad

Recently uploaded (20)

PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
CDH. pptx
AneetaSharma15
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Virus sequence retrieval from NCBI database
yamunaK13
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
CDH. pptx
AneetaSharma15
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 

Relational Algebra in DBMS power ppoint pesenetation

  • 2. Relational Algebra • Relational algebra in DBMS is a procedural query language. • Queries in relational algebra are performed using operators. An operator can be either unary or binary. • Relational Algebra is a procedural query language. Relational algebra mainly provides a theoretical foundation for relational databases and SQL. • The main purpose of using Relational Algebra is to define operators that transform one or more input relations into an output relation. • Relational Algebra came in 1970 and was given by Edgar F. Codd (Father of DBMS). It is also known as Procedural Query Language(PQL) as in PQL, a programmer/user has to mention two things, "What to Do" and "How to Do".
  • 3. Relational Operations in DBMS • Relational algebra is a procedural query language. It gives a step by step process to obtain the result of the query. • In Relational Algebra, we have two types of Operations. • Basic Operations • Derived Operations • Applying these operations over relations/tables will give us new relations as output.
  • 5. Select Operation (σ) • Select (σ) • Select operation is done by Selection Operator which is represented by "sigma"(σ). It is used to retrieve tuples(rows) from the table where the given condition is satisfied. It is a unary operator means it requires only one operand. • Notation : σ p(R) • Where σ is used to represent SELECTION • R is used to represent RELATION • p is the logic formula • Example: σ AGE=20 (STUDENT) Types of Relational operation
  • 6. Select Operation (σ) • where σ stands for selecting tuples (rows) and r stands for relation (table) name. p is prepositional logic formula which may use connectors like and, or, and not. These terms may use relational operators like = , ≠ , ≥ , < , > , ≤ . • Example 1: σsubject = "database"(Books) • Output : Selects rows whose subject is 'database' from books table. • Example 2: σ subject = "database" and price = "450"(Books) • Output : Selects rows from books where subject is 'database' and 'price' is 450. • Example 3: σ subject = "database" and price = "450" or year > "2010"(Books) • Output : Selects rows from books where subject is 'database' and 'price' is 450 or those books published after 2010.
  • 7. Project Operation (∏) • Project (∏) • Project operation is done by Projection Operator which is represented by "pi"(∏). • It is used to retrieve certain attributes(columns) from the table. • It is also known as vertical partitioning as it separates the table vertically. It is also a unary operator. • Notation: ∏ A1, A2, … An (R) • where A1, A2 , An are column (attribute) names of relation R. • Duplicate rows are automatically eliminated in the output. • Example: ∏ subject, author (Books) • Display values from columns subject and author from the relation Books.
  • 8. Union Operation ( ) ∪ • Union ( ) ∪ • Union operation is done by Union Operator which is represented by "union"( ). ∪ • It is the same as the union operator from set theory, i.e., it selects all tuples from both relations but with the exception that for the union of two relations/tables both relations must have the same set of Attributes. • It is a binary operator as it requires two operands. Notation: R S ∪ Where R is the first relation S is the second relation • If relations don't have the same set of attributes, then the union of such relations will result in NULL. • ∏ NAME(STUDENT) ∏ ∪ NAME(EMPLOYEE)
  • 9. Intersection Operation (∩) • Intersection (∩) • Intersection operation is done by Intersection Operator which is represented by "intersection"(∩). • It is the same as the intersection operator from set theory, i.e., it selects all the tuples which are present in both relations. • It is a binary operator as it requires two operands. Also, it eliminates duplicates. Notation : R ∩ S Where R is the first relation S is the second relation • Example : we want the names which are present in STUDENT as well as in EMPLOYEE relation, Relations we used in Basic Operations. • ∏ NAME(STUDENT) ∩ ∏ NAME(EMPLOYEE)
  • 10. Set Difference (−) • Set Difference (-) • Set Difference as its name indicates is the difference between two relations (R-S). • It is denoted by a "Hyphen"(-) and it returns all the tuples(rows) which are in relation R but not in relation S. • It is also a binary operator. Notation : R - S Where R is the first relation S is the second relation • Just like union, the set difference also comes with the exception of the same set of attributes in both relations.
  • 11. Cartesian Product (Χ): • Cartesian product (X) • Cartesian product is denoted by the "X" symbol. • we have two relations R and S. Cartesian product will combine every tuple(row) from R with all the tuples from S. • It is also a binary operator. • Notation: R X S Where R is the first relation S is the second relation • Example: Π author (Books) X Π author (Articles)
  • 12. Rename Operation (ρ) • Rename (ρ) • Rename operation is denoted by "Rho"(ρ). • As its name suggests it is used to rename the output relation. Rename operator too is a binary operator. • Notation: ρ(R,S) Where R is the new relation name S is the old relation name • we are fetching the names of students from STUDENT relation. We would like to rename this relation as STUDENT_NAME. • ρ(STUDENT_NAME,∏ NAME(STUDENT))
  • 13. Overview • Select (σ) is used to retrieve tuples(rows) based on certain conditions. • Project (∏) is used to retrieve attributes(columns) from the relation. • Union ( ) ∪ is used to retrieve all the tuples from two relations. • Set Difference (-) is used to retrieve the tuples which are present in R but not in S(R-S). • Cartesian product (X) is used to combine each tuple from the first relation with each tuple from the second relation. • Rename (ρ) is used to rename the output relation.
  • 14. Division (/): • Division (÷) • Division Operation is represented by "division"(÷ or /) operator and is used in queries that involve keywords "every", "all", etc. Notation : R(X,Y)/S(Y) Here, R is the first relation from which data is retrieved. S is the second relation that will help to retrieve the data.
  • 15. • X and Y are the attributes/columns present in relation. We can have multiple attributes in relation, but keep in mind that attributes of S must be a proper subset of attributes of R. • For each corresponding value of Y, the above notation will return us the value of X from tuple<X,Y> which exists everywhere. • It's a bit difficult to understand this in a theoretical way, but you will understand this with an example. • Let's have two relations, ENROLLED and COURSE. ENROLLED consist of two attributes STUDENT_ID and COURSE_ID. It denotes the map of students who are enrolled in given courses. • COURSE contains the list of courses available. • ENROLLED(STUDENT_ID, COURSE_ID)/COURSE(COURSE_ID)
  • 16. SQL JOINS • SQL Join statement is used to combine data or rows from two or more tables based on a common field between them. Different types of Joins are as follows: • INNER JOIN • LEFT JOIN • RIGHT JOIN • FULL JOIN • NATURAL JOIN
  • 17. SQL JOINS • JOIN is an SQL clause used to query and access data from multiple tables, based on logical relationships between those tables.
  • 18. INNER JOIN • A. INNER JOIN • The INNER JOIN keyword selects all rows from both the tables as long as the condition is satisfied. This keyword will create the result-set by combining all rows from both the tables where the condition satisfies i.e value of the common field will be the same. • SELECT table1.column1,table1.column2,table2.column1,.... FROM table1 INNER JOIN table2 ON table1.matching_column = table2.matching_column; table1: First table. table2: Second table matching_column: Column common to both the tables.
  • 19. INNER JOIN • Example Queries(INNER JOIN) • This query will show the names and age of students enrolled in different courses. • SELECT StudentCourse.COURSE_ID, Student.NAME, Student.AGE FROM Student INNER JOIN StudentCourse ON Student.ROLL_NO = StudentCourse.ROLL_NO;
  • 20. LEFT JOIN • B. LEFT JOIN • This join returns all the rows of the table on the left side of the join and matches rows for the table on the right side of the join. For the rows for which there is no matching row on the right side, the result- set will contain null. LEFT JOIN is also known as LEFT OUTER JOIN. • Syntax: • SELECT table1.column1,table1.column2,table2.column1,.... FROM table1 LEFT JOIN table2 ON table1.matching_column = table2.matching_column; table1: First table. table2: Second table matching_column: Column common to both the tables.
  • 21. • Example Queries(LEFT JOIN): • SELECT Student.NAME,StudentCourse.COURSE_ID FROM Student LEFT JOIN StudentCourse ON StudentCourse.ROLL_NO = Student.ROLL_NO; Output: LEFT JOIN
  • 22. RIGHT JOIN • RIGHT JOIN • RIGHT JOIN is similar to LEFT JOIN. This join returns all the rows of the table on the right side of the join and matching rows for the table on the left side of the join. For the rows for which there is no matching row on the left side, the result- set will contain null. RIGHT JOIN is also known as RIGHT OUTER JOIN. • Syntax: • SELECT table1.column1,table1.column2,table2.column1,.... FROM table1 RIGHT JOIN table2 ON table1.matching_column = table2.matching_column; table1: First table. table2: Second table matching_column: Column common to both the tables.
  • 23. • Example Queries(RIGHT JOIN): • SELECT Student.NAME,StudentCourse.COURSE_ID FROM Student RIGHT JOIN StudentCourse ON StudentCourse.ROLL_NO = Student.ROLL_NO; Output:
  • 24. FULL JOIN • FULL JOIN • FULL JOIN creates the result-set by combining results of both LEFT JOIN and RIGHT JOIN. The result-set will contain all the rows from both tables. For the rows for which there is no matching, the result-set will contain NULL values.
  • 25. FULL JOIN • Syntax: • SELECT table1.column1,table1.column2,table2.column1,.... FROM table1 FULL JOIN table2 ON table1.matching_column = table2.matching_column; table1: First table. table2: Second table matching_column: Column common to both the tables.
  • 26. FULL JOIN • Example Queries(FULL JOIN): • SELECT Student.NAME,StudentCourse.COURSE_ID FROM Student FULL JOIN StudentCourse ON StudentCourse.ROLL_NO = Student.ROLL_NO; Output: NAME COURSE_I D HARSH 1 PRATIK 2 RIYANKA 2 DEEP 3 SAPTARHI 1 DHANRAJ NULL ROHIT NULL NIRAJ NULL NULL 4 NULL 5 NULL 4
  • 27. Natural join • E. Natural join (?) • Natural join can join tables based on the common columns in the tables being joined. A natural join returns all rows by matching values in common columns having same name and data type of columns and that column should be present in both tables. • Both table must have at list one common column with same column name and same data type. • The two table are joined using Cross join. • DBMS will look for a common column with same name and data type Tuples having exactly same values in common columns are kept in result.
  • 28. Natural join Employee Emp_id Emp_name Dept_id 1 Ram 10 2 Jon 30 3 Bob 50 Department Dept_id Dept_name 10 IT 30 HR 40 TIS Query: Find all Employees and their respective departments. Solution: (Employee) ? (Department) Emp_id Emp_name Dept_id Dept_id Dept_name 1 Ram 10 10 IT 2 Jon 30 30 HR Employee data Department data Example: