SlideShare a Scribd company logo
1 of 26
Download to read offline
Relational Algebra is a procedural query language. Relational algebra mainly provides a theoretical foundation for
relational databases and SQL.
Types of Relational operation
1. Select Operation:
• The select operation selects tuples that satisfy a given predicate.
• It is denoted by sigma (σ).
Syntax: σ p(r)
Where:
• σ - is used for selection prediction
r - is used for relation
p - is used as a propositional logic formula which may use connectors
like: AND OR and NOT. These relational can use as relational operators
like =, ≠, ≥, <, >, ≤.
BRANCH_NAME LOAN_NO AMOUNT
Downtown L-17 1000
Redwood L-23 2000
Perryride L-15 1500
Downtown L-14 1500
Mianus L-13 500
Roundhill L-11 900
Perryride L-16 1300
σ BRANCH_NAME="perryride" (LOAN)
BRANCH_
NAME
LOAN_NO AMOUNT
Perryride L-15 1500
Perryride L-16 1300
Output:
2. Project Operation:
• This operation shows the list of those attributes that we wish to
appear in the result.
• It is denoted by ∏
• ∏ (R) A1, A2, An
NAME STREET CITY
Jones Main Harrison
Smith North Rye
Hays Main Harrison
Curry North Rye
Johnson Alma Brooklyn
Brooks Senator Brooklyn
Example: CUSTOMER RELATION
∏ NAME, CITY (CUSTOMER)
3. Union Operation:
•Suppose there are two tuples R and S. The union operation contains all
the tuples that are either in R or S or both in R & S.
•It eliminates the duplicate tuples. It is denoted by ∪.
SYNTAX - R ∪ S
A union operation must hold the following condition:
•R and S must have the attribute of the same number.
•Duplicate tuples are eliminated automatically.
DEPOSITOR RELATION
CUSTOMER_NAME ACCOUNT_NO
Johnson A-101
Smith A-121
Mayes A-321
Turner A-176
Johnson A-273
Jones A-472
Lindsay A-284
BORROW RELATION
CUSTOMER_NAME LOAN_NO
Jones L-17
Smith L-23
Hayes L-15
Jackson L-14
Curry L-93
Smith L-11
Williams L-17
∏ CUSTOMER_NAME (BORROW) ∪ ∏ CUSTOMER_NAME (DEPOSITOR)
Output:
CUSTOMER_NAME
Johnson
Smith
Hayes
Turner
Jones
Lindsay
Jackson
Curry
4. Set Intersection:
• Suppose there are two tuples R and S. The set intersection
operation contains all tuples that are in both R & S.
• It is denoted by intersection ∩.
• Notation: R ∩ S
∏ CUSTOMER_NAME (BORROW) ∩ ∏ CUSTOMER_NAME
(DEPOSITOR)
Output:
CUSTOMER_NAME
Smith
Jones
5. Set Difference:
Suppose there are two tuples R and S. The set intersection operation
contains all tuples that are in R but not in S.
It is denoted by intersection minus (-).
Notation: R - S
∏ CUSTOMER_NAME (BORROW) - ∏ CUSTOMER_NAME
(DEPOSITOR)
Output:
CUSTOMER_NAME
Jackson
Hayes
DEPARTMENT
DEPT_NODEPT_NAME
A Marketing
B Sales
C Legal
EMPLOYEE
EMP_ID EMP_NAME EMP_DEPT
1 Smith A
2 Harry C
3 John B
DEPARTMENT
DEPT_NO DEPT_NAME
A Marketing
B Sales
C Legal
Input:
EMPLOYEE X DEPARTMENT
Output:
EMP_ID EMP_NAME EMP_DEPT DEPT_NO DEPT_NAME
1 Smith A A Marketing
1 Smith A B Sales
1 Smith A C Legal
2 Harry C A Marketing
2 Harry C B Sales
2 Harry C C Legal
3 John B A Marketing
3 John B B Sales
3 John B C Legal
7. Rename Operation:
• The rename operation is used to rename the output relation. It is
denoted by rho (ρ).
• Example: We can use the rename operator to rename STUDENT relation
to STUDENT1.
• ρ(STUDENT1, STUDENT)
Join Operations:
A Join operation combines related tuples from different relations, if
and only if a given join condition is satisfied. It is denoted by ⋈.
Result:
EMP_CODE EMP_NAME SALARY
101 Stephan 50000
102 Jack 30000
103 Harry 25000
1. Natural Join:
A natural join is the set of tuples of all combinations in R and S that
are equal on their common attribute names.
It is denoted by ⋈.
Input:
∏EMP_NAME, SALARY (EMPLOYEE ⋈ SALARY)
Output:
EMP_NAME SALARY
Stephan 50000
Jack 30000
Harry 25000
What are Joins?
JOINS in SQL are commands which are used to combine rows from two or more tables, based
on a related column between those tables. There are predominantly used when a user is
trying to extract data from tables which have one-to-many or many-to-many relationships
between them.
Now, that you know what joins mean, let us next learn the different types of joins.
How many types of Joins are there in SQL?
There are mainly four types of joins that you need to understand. They are:
INNER JOIN
FULL JOIN
LEFT JOIN
RIGHT JOIN
INNER JOIN
This type of join returns those records which have matching values in both tables. So, if you
perform an INNER join operation between the Employee table and the Projects table, all
the tuples which have matching values in both the tables will be given as output.
Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1
INNER JOIN Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
SELECT Employee.EmpID, Employee.EmpFname, Employee.EmpLname,
Projects.ProjectID, Projects.ProjectName
FROM Employee
INNER JOIN Projects ON Employee.EmpID=Projects.EmpID;
LEFT JOIN
The LEFT JOIN or the LEFT OUTER JOIN returns all the records from the left table and also those
records which satisfy a condition from the right table. Also, for the records having no matching
values in the right table, the output or the result-set will contain the NULL values.
Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1
LEFT JOIN Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
EXAMPLE:
SELECT Employee.EmpFname, Employee.EmpLname, Projects.ProjectID, Projects.ProjectName
FROM Employee
LEFT JOIN
ON Employee.EmpID = Projects.EmpID ;
RIGHT JOIN
The RIGHT JOIN or the RIGHT OUTER JOIN returns all the records from the
right table and also those records which satisfy a condition from the left table.
Also, for the records having no matching values in the left table, the output or
the result-set will contain the NULL values.
Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1
RIGHT JOIN Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
SELECT Employee.EmpFname, Employee.EmpLname, Projects.ProjectID,
Projects.ProjectName
FROM Employee
RIGHT JOIN
ON Employee.EmpID = Projects.EmpID;
FULL JOIN
Full Join or the Full Outer Join returns all those records which either have a match in the
left(Table1) or the right(Table2) table.
Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1
FULL JOIN Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
Example:
SELECT Employee.EmpFname, Employee.EmpLname, Projects.ProjectID
FROM Employee
FULL JOIN Projects
ON Employee.EmpID = Projects.EmpID;
1695304562_RELATIONAL_ALGEBRA.pdf

More Related Content

Similar to 1695304562_RELATIONAL_ALGEBRA.pdf

Unit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operationUnit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operationshindhe1098cv
 
chapter 5-Relational Algebra and calculus.ppt
chapter 5-Relational Algebra and calculus.pptchapter 5-Relational Algebra and calculus.ppt
chapter 5-Relational Algebra and calculus.pptMisganawAbeje1
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational AlgebraAmin Omi
 
3._Relational_Algebra.pptx:Basics of relation algebra
3._Relational_Algebra.pptx:Basics of relation algebra3._Relational_Algebra.pptx:Basics of relation algebra
3._Relational_Algebra.pptx:Basics of relation algebraZakriyaMalik2
 
Lesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdfLesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdfHasankaWijesinghe1
 
Module 2-2.ppt
Module 2-2.pptModule 2-2.ppt
Module 2-2.pptShylaja40
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMSkoolkampus
 
Chapter – 5 Relational Algebra.pdf
Chapter – 5 Relational Algebra.pdfChapter – 5 Relational Algebra.pdf
Chapter – 5 Relational Algebra.pdfTamiratDejene1
 
Relational algebr
Relational algebrRelational algebr
Relational algebrVisakh V
 
Relational operation final
Relational operation finalRelational operation final
Relational operation finalStudent
 
E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2Mukund Trivedi
 
E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)Mukund Trivedi
 
E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)Mukund Trivedi
 
Assignment 4
Assignment 4Assignment 4
Assignment 4SneaK3
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operationsSanthiNivas
 

Similar to 1695304562_RELATIONAL_ALGEBRA.pdf (20)

Unit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operationUnit2 -DBMS.ppt with type of job operation
Unit2 -DBMS.ppt with type of job operation
 
chapter 5-Relational Algebra and calculus.ppt
chapter 5-Relational Algebra and calculus.pptchapter 5-Relational Algebra and calculus.ppt
chapter 5-Relational Algebra and calculus.ppt
 
Unit04 dbms
Unit04 dbmsUnit04 dbms
Unit04 dbms
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational Algebra
 
3._Relational_Algebra.pptx:Basics of relation algebra
3._Relational_Algebra.pptx:Basics of relation algebra3._Relational_Algebra.pptx:Basics of relation algebra
3._Relational_Algebra.pptx:Basics of relation algebra
 
Lesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdfLesson 6 - Relational Algebra.pdf
Lesson 6 - Relational Algebra.pdf
 
Module 2-2.ppt
Module 2-2.pptModule 2-2.ppt
Module 2-2.ppt
 
Cs501 rel algebra
Cs501 rel algebraCs501 rel algebra
Cs501 rel algebra
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
 
Chapter – 5 Relational Algebra.pdf
Chapter – 5 Relational Algebra.pdfChapter – 5 Relational Algebra.pdf
Chapter – 5 Relational Algebra.pdf
 
Relational algebr
Relational algebrRelational algebr
Relational algebr
 
Relational operation final
Relational operation finalRelational operation final
Relational operation final
 
E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2E212d9a797dbms chapter3 b.sc2
E212d9a797dbms chapter3 b.sc2
 
E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)E212d9a797dbms chapter3 b.sc2 (2)
E212d9a797dbms chapter3 b.sc2 (2)
 
E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)E212d9a797dbms chapter3 b.sc2 (1)
E212d9a797dbms chapter3 b.sc2 (1)
 
Relational model
Relational modelRelational model
Relational model
 
Relational+algebra (1)
Relational+algebra (1)Relational+algebra (1)
Relational+algebra (1)
 
DDL and DML statements.pptx
DDL and DML statements.pptxDDL and DML statements.pptx
DDL and DML statements.pptx
 
Assignment 4
Assignment 4Assignment 4
Assignment 4
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operations
 

Recently uploaded

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 

Recently uploaded (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 

1695304562_RELATIONAL_ALGEBRA.pdf

  • 1. Relational Algebra is a procedural query language. Relational algebra mainly provides a theoretical foundation for relational databases and SQL. Types of Relational operation
  • 2. 1. Select Operation: • The select operation selects tuples that satisfy a given predicate. • It is denoted by sigma (σ). Syntax: σ p(r) Where: • σ - is used for selection prediction r - is used for relation p - is used as a propositional logic formula which may use connectors like: AND OR and NOT. These relational can use as relational operators like =, ≠, ≥, <, >, ≤.
  • 3. BRANCH_NAME LOAN_NO AMOUNT Downtown L-17 1000 Redwood L-23 2000 Perryride L-15 1500 Downtown L-14 1500 Mianus L-13 500 Roundhill L-11 900 Perryride L-16 1300 σ BRANCH_NAME="perryride" (LOAN) BRANCH_ NAME LOAN_NO AMOUNT Perryride L-15 1500 Perryride L-16 1300 Output:
  • 4. 2. Project Operation: • This operation shows the list of those attributes that we wish to appear in the result. • It is denoted by ∏ • ∏ (R) A1, A2, An NAME STREET CITY Jones Main Harrison Smith North Rye Hays Main Harrison Curry North Rye Johnson Alma Brooklyn Brooks Senator Brooklyn Example: CUSTOMER RELATION ∏ NAME, CITY (CUSTOMER)
  • 5. 3. Union Operation: •Suppose there are two tuples R and S. The union operation contains all the tuples that are either in R or S or both in R & S. •It eliminates the duplicate tuples. It is denoted by ∪. SYNTAX - R ∪ S A union operation must hold the following condition: •R and S must have the attribute of the same number. •Duplicate tuples are eliminated automatically.
  • 6. DEPOSITOR RELATION CUSTOMER_NAME ACCOUNT_NO Johnson A-101 Smith A-121 Mayes A-321 Turner A-176 Johnson A-273 Jones A-472 Lindsay A-284 BORROW RELATION CUSTOMER_NAME LOAN_NO Jones L-17 Smith L-23 Hayes L-15 Jackson L-14 Curry L-93 Smith L-11 Williams L-17 ∏ CUSTOMER_NAME (BORROW) ∪ ∏ CUSTOMER_NAME (DEPOSITOR) Output: CUSTOMER_NAME Johnson Smith Hayes Turner Jones Lindsay Jackson Curry
  • 7. 4. Set Intersection: • Suppose there are two tuples R and S. The set intersection operation contains all tuples that are in both R & S. • It is denoted by intersection ∩. • Notation: R ∩ S ∏ CUSTOMER_NAME (BORROW) ∩ ∏ CUSTOMER_NAME (DEPOSITOR) Output: CUSTOMER_NAME Smith Jones
  • 8. 5. Set Difference: Suppose there are two tuples R and S. The set intersection operation contains all tuples that are in R but not in S. It is denoted by intersection minus (-). Notation: R - S ∏ CUSTOMER_NAME (BORROW) - ∏ CUSTOMER_NAME (DEPOSITOR) Output: CUSTOMER_NAME Jackson Hayes
  • 9. DEPARTMENT DEPT_NODEPT_NAME A Marketing B Sales C Legal EMPLOYEE EMP_ID EMP_NAME EMP_DEPT 1 Smith A 2 Harry C 3 John B DEPARTMENT DEPT_NO DEPT_NAME A Marketing B Sales C Legal
  • 10. Input: EMPLOYEE X DEPARTMENT Output: EMP_ID EMP_NAME EMP_DEPT DEPT_NO DEPT_NAME 1 Smith A A Marketing 1 Smith A B Sales 1 Smith A C Legal 2 Harry C A Marketing 2 Harry C B Sales 2 Harry C C Legal 3 John B A Marketing 3 John B B Sales 3 John B C Legal
  • 11. 7. Rename Operation: • The rename operation is used to rename the output relation. It is denoted by rho (ρ). • Example: We can use the rename operator to rename STUDENT relation to STUDENT1. • ρ(STUDENT1, STUDENT)
  • 12. Join Operations: A Join operation combines related tuples from different relations, if and only if a given join condition is satisfied. It is denoted by ⋈.
  • 13. Result: EMP_CODE EMP_NAME SALARY 101 Stephan 50000 102 Jack 30000 103 Harry 25000
  • 14. 1. Natural Join: A natural join is the set of tuples of all combinations in R and S that are equal on their common attribute names. It is denoted by ⋈. Input: ∏EMP_NAME, SALARY (EMPLOYEE ⋈ SALARY) Output: EMP_NAME SALARY Stephan 50000 Jack 30000 Harry 25000
  • 15. What are Joins? JOINS in SQL are commands which are used to combine rows from two or more tables, based on a related column between those tables. There are predominantly used when a user is trying to extract data from tables which have one-to-many or many-to-many relationships between them. Now, that you know what joins mean, let us next learn the different types of joins. How many types of Joins are there in SQL? There are mainly four types of joins that you need to understand. They are: INNER JOIN FULL JOIN LEFT JOIN RIGHT JOIN
  • 16.
  • 17.
  • 18.
  • 19. INNER JOIN This type of join returns those records which have matching values in both tables. So, if you perform an INNER join operation between the Employee table and the Projects table, all the tuples which have matching values in both the tables will be given as output. Syntax: SELECT Table1.Column1,Table1.Column2,Table2.Column1,.... FROM Table1 INNER JOIN Table2 ON Table1.MatchingColumnName = Table2.MatchingColumnName; SELECT Employee.EmpID, Employee.EmpFname, Employee.EmpLname, Projects.ProjectID, Projects.ProjectName FROM Employee INNER JOIN Projects ON Employee.EmpID=Projects.EmpID;
  • 20.
  • 21. LEFT JOIN The LEFT JOIN or the LEFT OUTER JOIN returns all the records from the left table and also those records which satisfy a condition from the right table. Also, for the records having no matching values in the right table, the output or the result-set will contain the NULL values. Syntax: SELECT Table1.Column1,Table1.Column2,Table2.Column1,.... FROM Table1 LEFT JOIN Table2 ON Table1.MatchingColumnName = Table2.MatchingColumnName; EXAMPLE: SELECT Employee.EmpFname, Employee.EmpLname, Projects.ProjectID, Projects.ProjectName FROM Employee LEFT JOIN ON Employee.EmpID = Projects.EmpID ;
  • 22.
  • 23. RIGHT JOIN The RIGHT JOIN or the RIGHT OUTER JOIN returns all the records from the right table and also those records which satisfy a condition from the left table. Also, for the records having no matching values in the left table, the output or the result-set will contain the NULL values. Syntax: SELECT Table1.Column1,Table1.Column2,Table2.Column1,.... FROM Table1 RIGHT JOIN Table2 ON Table1.MatchingColumnName = Table2.MatchingColumnName;
  • 24. SELECT Employee.EmpFname, Employee.EmpLname, Projects.ProjectID, Projects.ProjectName FROM Employee RIGHT JOIN ON Employee.EmpID = Projects.EmpID;
  • 25. FULL JOIN Full Join or the Full Outer Join returns all those records which either have a match in the left(Table1) or the right(Table2) table. Syntax: SELECT Table1.Column1,Table1.Column2,Table2.Column1,.... FROM Table1 FULL JOIN Table2 ON Table1.MatchingColumnName = Table2.MatchingColumnName; Example: SELECT Employee.EmpFname, Employee.EmpLname, Projects.ProjectID FROM Employee FULL JOIN Projects ON Employee.EmpID = Projects.EmpID;