SlideShare a Scribd company logo
1 of 3
Download to read offline
Query Examples in Relational Algebra and SQL
Consider the relation schemas as follows.
works(person name, company name, salary);
lives(person name, street, city);
located in(company name, city);
managers(person name, manager name);
where manager name refers to person name.
a Find the names of the persons who work for company ’FBC’ (company name=’FBC’).
Relational algebra:
 ¢¡¢£¥¤§¦©¨!$# #%$¥')(§0!$1%$#32 #%$1465 718@9@51'BADC¥E©F¢G¥H@H
SQL:
Select person_name
From works
Where company_name = ’FBC’
b List the names of the persons who work for company ’FBC’ along with the cities they live in.
Relational algebra:
I¢P¥Q ¡¢£SR¢TU VRXW¢Y`a!$# #%$b(§0!$1%$#32 #%$14 5 718@9 5 'BADC¥E©F¢G¥H
cXd ¡Uef§g¥h¢¡pirqs I¢P¥Q ¡¢£SR¢TU VRXW¢Yut$vs¦¢g¥h¢¡¢£
 ¢¡¢£¥¤§¦©¨wa!$# #%$x 01y$€@2S' cXd ¡Uef§g¥h¢¡pirqXH
SQL:
Select lives.person_name, city
From works, lives
Where company_name = ’FBC’ and
works.person_name = lives.person_name
c Find the persons who work for company ’FBC’ with a salary of more than 10000. List the names of these
persons along with the streets and cities where they live.
Relational algebra:
 ¡U §£UT©q‚£XƒU„XRXW¢Y`a(§0!$1%$#32 #%$14 5 718@9 5 '†…pTU V‡§£SH
I¢P¥Q ¡©ˆ‰g¥¨ d W‰g¥¢‘ P ¦’!$# #%$b(§%1“1%@2b”6•$–1–1–1–S'  ¡U §£UT©q‚£XƒU„XRXW¢YSH
 ¢¡¢£¥¤§¦©¨w I¢P¥Q ¡©ˆ‰g¥¨ d W‰g¥¢‘ P ¦—t$vs¦¢g¥h¢¡¢£
SQL:
Select lives.person_name, stree, city
From lives, works
Where lives.person_name = works.person_name and salary  10000
and works.company_name = ’FBC’
1
d Find the names of the persons who live and work in the same city.
Relational algebra:
ˆpTU V‡fT¡  P ¨‚g©T©qs!$# #%$x 01y$€@2S'†…pTU V‡§£Dt$vs¦XT¡  P ¨¢¡£¢ grq¢H
 ¢¡¢£¥¤§¦©¨wa!$# #%$b(§01y$€@2@4¥¤§¦ 01y$€@2S'†ˆpTU V‡fT¡  P ¨‚g©T©q©¨ '¦¢g¥h¢¡¢£©H@H
SQL:
Select person_name
From works, lives, locates_in
Where works.person_name = lives.person_name and
works.company_name = located_in.company_name and
located_in.city = lives.city
e Find the names of the persons who live in the same city and on the same street as their managers.
Relational algebra:
 ¢¢£  ¢¢  (V%$#%@ #%$14 !¦ !$# #%$¥'#D'¦¢g¥h¢¡¢£SH t$v Q‚P q P ¢¡U XH$¨% '¦¢g¥h¢¡¢£SH
‘ P¥Q ¡V‘U¨V ¢¡V¡U¨Y§g¥¨Ve`a('!¦ $€131€34 !¦ (€131€0)1'!¦ 01y$€@2@4 !¦ 01y$€@2¥'  ¢¢£  ¢¢UH
 ¢¡¢£¥¤§¦©¨wa¡'!¦ !$# #%$¥'$‘ P¥Q ¡V‘U¨V ¢¡V¡U¨Y§g¥¨Ve©H
SQL:
Select e.person_name
From lives e, lives m, managers
Where e.person_name = managers.person_name and
m.person_name = managers.manager_name and
e.street = m.street and e.city = m.city
f Find the names of the persons who do not work for company ’FBC’.
Relational algebra:
 ¡U §£UT©qR¢TU VRXW¢Y`!$# #%$(§0!$1%$#@@2 #%$14 5 718@9 5 '†…pTU V‡§£SH
ˆpTU V‡  ¡U §£UT©q‚£’a!$# #%$S'†…pTU V‡§£SH
 ¢¡¢£¥¤§¦©¨wˆpTU V‡  ¡U §£UT©q‚£$2  ¡U §£UT©qR¢TU VRXW¢Y
SQL:
Select person_name
From works
Where person_name not in (Select person_name
From works
Where company_name = ’FBC’)
g Find the persons whose salaries are more than the salary of everybody who work for company ’SBC’.
Relational algebra:
‘ P ¦ P  ‚g©¡¢£XƒU„‘©W¢Yua‚%1“1%@2 (§0!$1%$#32 #%$14 5 (8@9 5 '†…pTU V‡§£SH
ˆpTU V‡§£¥ˆ‰g¥¨ d ‘ P ¦ P  Ve¢ƒU„‘SW¢YD…pTU V‡§£3¨4 '$‘ P ¦ P  ‚g©¡¢£XƒU„‘©W¢YSH
¢P  Xq‚£©f¡¢£V£ cXdpP qp‘VT Q ¡V‘SW¢YDa!$# #%$b(§%1“1%@2§5 (6¦ %1“1%@2S'†ˆpTU V‡§£¥ˆ‰g¥¨ d ‘ P ¦ P  Vepƒ©„‘SW¢Y¥H
 ¢¡¢£¥¤§¦©¨wa!$# #%$S'†…pTU V‡§£SH72 ¢P  Xq‚£©f¡¢£V£ cXdpP qp‘VT Q ¡V‘SW¢Y
2
SQL:
Select person_name
From works
Where salary  all (Select salary
From works
Where company_name = ’SBC’)
h Find the names of the companies that is located in every city where company ’SBC’ is located in.
Relational algebra:
 ¦V¦X‘©W¢YVY§g¥¨‚g©¡¢£’‚01y$€@2 (§0!$1%$#32 #%$14 5 (8@9 5 '¦XT¡  P ¨¢¡£¢ grq¢H
i Q‚P ‚grq  ¦V¦UYT Q¡ pP qVe  ¨  ¦X¦X‘SW¢YVfVT¡  P ¨‚gST©q§£ a‚0!$1%$#32 #%$S'£¢)C¥¤§¦©¨  H ¨  ¦V¦X‘©W¢YVY§g¥¨‚g©¡¢£
I TU¨¢¡ P ¦V¦©e c  X¤p¡D i Q‚P ‚grq  ¦V¦UYT Q¡ pP qe  ¨  ¦V¦U‘©WYVfT  P ¨‚gST©q‚£ 2 ¦XT¡  P ¨¢¡£¢ grq
 ¢¡¢£¥¤§¦©¨wa‚0!$1%$#32 #%$S'¦XT¡  P ¨¢¡£¢ grq¢H72 ‚0!$1%$#32 #%$S' I TU¨¢¡ P ¦V¦©e c  X¤p¡¥H
Relational algebra (another solution):
 ¦V¦X‘©W¢YVY§g¥¨‚g©¡¢£’‚01y$€@2 (§0!$1%$#32 #%$14 5 (8@9 5 '¦XT¡  P ¨¢¡£¢ grq¢H
 ¢¡¢£¥¤§¦©¨w ¦XT¡  P ¨¢¡£¢ grq   ¦V¦X‘©W¢YVY§g¥¨‚g©¡¢£
SQL:
Select company_name
From located_in t
Where (Select city
From located_in s
Where t.company_name = s.company_name)
contains (Select city
From located_in s1
Where s1.company_name = ’SBC’)
SQL (another solution):
Select company_name
From located_in t
Where not exists
(Select *
From located_in s
Where s.company_name = ’SBC’ and
s.city not in
(Select city
From located_in l
Where l.company_name = t.company_name))
3

More Related Content

What's hot

Book Store Management System - Database Design - 2021
Book Store Management System - Database Design - 2021Book Store Management System - Database Design - 2021
Book Store Management System - Database Design - 2021Bharat Chawda
 
String matching algorithms(knuth morris-pratt)
String matching algorithms(knuth morris-pratt)String matching algorithms(knuth morris-pratt)
String matching algorithms(knuth morris-pratt)Neel Shah
 
IRJET- Blockchain based Fake Product Identification in Supply Chain
IRJET- Blockchain based Fake Product Identification in Supply ChainIRJET- Blockchain based Fake Product Identification in Supply Chain
IRJET- Blockchain based Fake Product Identification in Supply ChainIRJET Journal
 
ELECTRICITY BILLING SYSTEM (1).pptx
ELECTRICITY BILLING SYSTEM (1).pptxELECTRICITY BILLING SYSTEM (1).pptx
ELECTRICITY BILLING SYSTEM (1).pptxABHISHEKJADHAV106697
 
Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked listRoshan Chaudhary
 
Simple Calendar Application using C
Simple Calendar Application using CSimple Calendar Application using C
Simple Calendar Application using Ccodewithc
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsArvind Krishnaa
 
Project of data structure
Project of data structureProject of data structure
Project of data structureUmme habiba
 
Hotel management
Hotel managementHotel management
Hotel managementArman Ahmed
 
Intelligent Weather Service
Intelligent Weather Service Intelligent Weather Service
Intelligent Weather Service Uday Sharma
 
Pharmacy management system
Pharmacy management systemPharmacy management system
Pharmacy management systemsudiahmad1
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
Book Selling Website Report
Book Selling Website ReportBook Selling Website Report
Book Selling Website ReportSaloni Bajaj
 
Employee Management System
Employee Management SystemEmployee Management System
Employee Management SystemMonotheist Sakib
 
e commerce project report,E-Commerce,Eshop,report
e commerce project report,E-Commerce,Eshop,reporte commerce project report,E-Commerce,Eshop,report
e commerce project report,E-Commerce,Eshop,reportBabluAgrahari
 
Online Quiz System Project Report
Online Quiz System Project Report Online Quiz System Project Report
Online Quiz System Project Report Kishan Maurya
 
Banking Management System Project
Banking Management System ProjectBanking Management System Project
Banking Management System ProjectChaudhry Sajid
 

What's hot (20)

Book Store Management System - Database Design - 2021
Book Store Management System - Database Design - 2021Book Store Management System - Database Design - 2021
Book Store Management System - Database Design - 2021
 
String matching algorithms(knuth morris-pratt)
String matching algorithms(knuth morris-pratt)String matching algorithms(knuth morris-pratt)
String matching algorithms(knuth morris-pratt)
 
IRJET- Blockchain based Fake Product Identification in Supply Chain
IRJET- Blockchain based Fake Product Identification in Supply ChainIRJET- Blockchain based Fake Product Identification in Supply Chain
IRJET- Blockchain based Fake Product Identification in Supply Chain
 
Bank Management System
Bank Management SystemBank Management System
Bank Management System
 
ELECTRICITY BILLING SYSTEM (1).pptx
ELECTRICITY BILLING SYSTEM (1).pptxELECTRICITY BILLING SYSTEM (1).pptx
ELECTRICITY BILLING SYSTEM (1).pptx
 
guess the number project.docx
guess the number  project.docxguess the number  project.docx
guess the number project.docx
 
Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked list
 
Simple Calendar Application using C
Simple Calendar Application using CSimple Calendar Application using C
Simple Calendar Application using C
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
 
Hotel management
Hotel managementHotel management
Hotel management
 
Intelligent Weather Service
Intelligent Weather Service Intelligent Weather Service
Intelligent Weather Service
 
Pharmacy management system
Pharmacy management systemPharmacy management system
Pharmacy management system
 
String matching algorithms
String matching algorithmsString matching algorithms
String matching algorithms
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Book Selling Website Report
Book Selling Website ReportBook Selling Website Report
Book Selling Website Report
 
Employee Management System
Employee Management SystemEmployee Management System
Employee Management System
 
e commerce project report,E-Commerce,Eshop,report
e commerce project report,E-Commerce,Eshop,reporte commerce project report,E-Commerce,Eshop,report
e commerce project report,E-Commerce,Eshop,report
 
Online Quiz System Project Report
Online Quiz System Project Report Online Quiz System Project Report
Online Quiz System Project Report
 
Banking Management System Project
Banking Management System ProjectBanking Management System Project
Banking Management System Project
 

Similar to Lecture5

[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04AnusAhmad
 
Pagination Done the Right Way
Pagination Done the Right WayPagination Done the Right Way
Pagination Done the Right WayMarkus Winand
 
Most Recent Samples
Most Recent SamplesMost Recent Samples
Most Recent SamplesNeil Myers
 
Outsourcing 3.0: the agile way
Outsourcing 3.0: the agile wayOutsourcing 3.0: the agile way
Outsourcing 3.0: the agile wayAlexey Krivitsky
 
Melbourne networking presentation 5.10
Melbourne networking presentation 5.10Melbourne networking presentation 5.10
Melbourne networking presentation 5.10Rob Lawson
 
GIS and Google Earth In Geography
GIS and Google Earth In GeographyGIS and Google Earth In Geography
GIS and Google Earth In GeographyOllie Bray
 
オープンデータプレゼン資料03
オープンデータプレゼン資料03オープンデータプレゼン資料03
オープンデータプレゼン資料03U_Kumi
 
Graph Databases
Graph DatabasesGraph Databases
Graph DatabasesJosh Adell
 
What the !@#$ is UX? A fun and concise introduction
What the !@#$ is UX? A fun and concise introductionWhat the !@#$ is UX? A fun and concise introduction
What the !@#$ is UX? A fun and concise introductionSean Buch
 

Similar to Lecture5 (11)

[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04[Www.pkbulk.blogspot.com]dbms04
[Www.pkbulk.blogspot.com]dbms04
 
Lf 2021 rates_vi
Lf 2021 rates_viLf 2021 rates_vi
Lf 2021 rates_vi
 
Pagination Done the Right Way
Pagination Done the Right WayPagination Done the Right Way
Pagination Done the Right Way
 
Most Recent Samples
Most Recent SamplesMost Recent Samples
Most Recent Samples
 
Outsourcing 3.0: the agile way
Outsourcing 3.0: the agile wayOutsourcing 3.0: the agile way
Outsourcing 3.0: the agile way
 
Melbourne networking presentation 5.10
Melbourne networking presentation 5.10Melbourne networking presentation 5.10
Melbourne networking presentation 5.10
 
GIS and Google Earth In Geography
GIS and Google Earth In GeographyGIS and Google Earth In Geography
GIS and Google Earth In Geography
 
オープンデータプレゼン資料03
オープンデータプレゼン資料03オープンデータプレゼン資料03
オープンデータプレゼン資料03
 
Graph Databases
Graph DatabasesGraph Databases
Graph Databases
 
What the !@#$ is UX? A fun and concise introduction
What the !@#$ is UX? A fun and concise introductionWhat the !@#$ is UX? A fun and concise introduction
What the !@#$ is UX? A fun and concise introduction
 
Graddivcurl1
Graddivcurl1Graddivcurl1
Graddivcurl1
 

Recently uploaded

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...caitlingebhard1
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governanceWSO2
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringWSO2
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....rightmanforbloodline
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Lecture5

  • 1. Query Examples in Relational Algebra and SQL Consider the relation schemas as follows. works(person name, company name, salary); lives(person name, street, city); located in(company name, city); managers(person name, manager name); where manager name refers to person name. a Find the names of the persons who work for company ’FBC’ (company name=’FBC’). Relational algebra:  ¢¡¢£¥¤§¦©¨!$# #%$¥')(§0!$1%$#32 #%$1465 718@9@51'BADC¥E©F¢G¥H@H SQL: Select person_name From works Where company_name = ’FBC’ b List the names of the persons who work for company ’FBC’ along with the cities they live in. Relational algebra: I¢P¥Q ¡¢£SR¢TU VRXW¢Y`a!$# #%$b(§0!$1%$#32 #%$14 5 718@9 5 'BADC¥E©F¢G¥H cXd ¡Uef§g¥h¢¡pirqs I¢P¥Q ¡¢£SR¢TU VRXW¢Yut$vs¦¢g¥h¢¡¢£  ¢¡¢£¥¤§¦©¨wa!$# #%$x 01y$€@2S' cXd ¡Uef§g¥h¢¡pirqXH SQL: Select lives.person_name, city From works, lives Where company_name = ’FBC’ and works.person_name = lives.person_name c Find the persons who work for company ’FBC’ with a salary of more than 10000. List the names of these persons along with the streets and cities where they live. Relational algebra:  ¡U §£UT©q‚£XƒU„XRXW¢Y`a(§0!$1%$#32 #%$14 5 718@9 5 '†…pTU V‡§£SH I¢P¥Q ¡©ˆ‰g¥¨ d W‰g¥¢‘ P ¦’!$# #%$b(§%1“1%@2b”6•$–1–1–1–S'  ¡U §£UT©q‚£XƒU„XRXW¢YSH  ¢¡¢£¥¤§¦©¨w I¢P¥Q ¡©ˆ‰g¥¨ d W‰g¥¢‘ P ¦—t$vs¦¢g¥h¢¡¢£ SQL: Select lives.person_name, stree, city From lives, works Where lives.person_name = works.person_name and salary 10000 and works.company_name = ’FBC’ 1
  • 2. d Find the names of the persons who live and work in the same city. Relational algebra: ˆpTU V‡fT¡  P ¨‚g©T©qs!$# #%$x 01y$€@2S'†…pTU V‡§£Dt$vs¦XT¡  P ¨¢¡£¢ grq¢H  ¢¡¢£¥¤§¦©¨wa!$# #%$b(§01y$€@2@4¥¤§¦ 01y$€@2S'†ˆpTU V‡fT¡  P ¨‚g©T©q©¨ '¦¢g¥h¢¡¢£©H@H SQL: Select person_name From works, lives, locates_in Where works.person_name = lives.person_name and works.company_name = located_in.company_name and located_in.city = lives.city e Find the names of the persons who live in the same city and on the same street as their managers. Relational algebra: ¢¢£ ¢¢ (V%$#%@ #%$14 !¦ !$# #%$¥'#D'¦¢g¥h¢¡¢£SH t$v Q‚P q P ¢¡U XH$¨% '¦¢g¥h¢¡¢£SH ‘ P¥Q ¡V‘U¨V ¢¡V¡U¨Y§g¥¨Ve`a('!¦ $€131€34 !¦ (€131€0)1'!¦ 01y$€@2@4 !¦ 01y$€@2¥' ¢¢£ ¢¢UH  ¢¡¢£¥¤§¦©¨wa¡'!¦ !$# #%$¥'$‘ P¥Q ¡V‘U¨V ¢¡V¡U¨Y§g¥¨Ve©H SQL: Select e.person_name From lives e, lives m, managers Where e.person_name = managers.person_name and m.person_name = managers.manager_name and e.street = m.street and e.city = m.city f Find the names of the persons who do not work for company ’FBC’. Relational algebra:  ¡U §£UT©qR¢TU VRXW¢Y`!$# #%$(§0!$1%$#@@2 #%$14 5 718@9 5 '†…pTU V‡§£SH ˆpTU V‡  ¡U §£UT©q‚£’a!$# #%$S'†…pTU V‡§£SH  ¢¡¢£¥¤§¦©¨wˆpTU V‡  ¡U §£UT©q‚£$2  ¡U §£UT©qR¢TU VRXW¢Y SQL: Select person_name From works Where person_name not in (Select person_name From works Where company_name = ’FBC’) g Find the persons whose salaries are more than the salary of everybody who work for company ’SBC’. Relational algebra: ‘ P ¦ P  ‚g©¡¢£XƒU„‘©W¢Yua‚%1“1%@2 (§0!$1%$#32 #%$14 5 (8@9 5 '†…pTU V‡§£SH ˆpTU V‡§£¥ˆ‰g¥¨ d ‘ P ¦ P  Ve¢ƒU„‘SW¢YD…pTU V‡§£3¨4 '$‘ P ¦ P  ‚g©¡¢£XƒU„‘©W¢YSH ¢P  Xq‚£©f¡¢£V£ cXdpP qp‘VT Q ¡V‘SW¢YDa!$# #%$b(§%1“1%@2§5 (6¦ %1“1%@2S'†ˆpTU V‡§£¥ˆ‰g¥¨ d ‘ P ¦ P  Vepƒ©„‘SW¢Y¥H  ¢¡¢£¥¤§¦©¨wa!$# #%$S'†…pTU V‡§£SH72 ¢P  Xq‚£©f¡¢£V£ cXdpP qp‘VT Q ¡V‘SW¢Y 2
  • 3. SQL: Select person_name From works Where salary all (Select salary From works Where company_name = ’SBC’) h Find the names of the companies that is located in every city where company ’SBC’ is located in. Relational algebra: ¦V¦X‘©W¢YVY§g¥¨‚g©¡¢£’‚01y$€@2 (§0!$1%$#32 #%$14 5 (8@9 5 '¦XT¡  P ¨¢¡£¢ grq¢H i Q‚P ‚grq ¦V¦UYT Q¡ pP qVe ¨ ¦X¦X‘SW¢YVfVT¡  P ¨‚gST©q§£ a‚0!$1%$#32 #%$S'£¢)C¥¤§¦©¨ H ¨ ¦V¦X‘©W¢YVY§g¥¨‚g©¡¢£ I TU¨¢¡ P ¦V¦©e c  X¤p¡D i Q‚P ‚grq ¦V¦UYT Q¡ pP qe ¨ ¦V¦U‘©WYVfT  P ¨‚gST©q‚£ 2 ¦XT¡  P ¨¢¡£¢ grq  ¢¡¢£¥¤§¦©¨wa‚0!$1%$#32 #%$S'¦XT¡  P ¨¢¡£¢ grq¢H72 ‚0!$1%$#32 #%$S' I TU¨¢¡ P ¦V¦©e c  X¤p¡¥H Relational algebra (another solution): ¦V¦X‘©W¢YVY§g¥¨‚g©¡¢£’‚01y$€@2 (§0!$1%$#32 #%$14 5 (8@9 5 '¦XT¡  P ¨¢¡£¢ grq¢H  ¢¡¢£¥¤§¦©¨w ¦XT¡  P ¨¢¡£¢ grq ¦V¦X‘©W¢YVY§g¥¨‚g©¡¢£ SQL: Select company_name From located_in t Where (Select city From located_in s Where t.company_name = s.company_name) contains (Select city From located_in s1 Where s1.company_name = ’SBC’) SQL (another solution): Select company_name From located_in t Where not exists (Select * From located_in s Where s.company_name = ’SBC’ and s.city not in (Select city From located_in l Where l.company_name = t.company_name)) 3