SlideShare a Scribd company logo
1 of 8
Complex Inner Joins I
2 Strategy for Complex Joins (A)  Identify which table columns contain the data needed. (B)  Use the PK-FK pairs that make each join to plot the join “pathway”.  Identify expressions to perform column and/or row operations needed and the clauses in which they belong.
3 Table Columns (32) List the last names of all current employees, their position titles, the last names of their supervisors and the departments in which they work.  The view should have 4 columns named “Supervisee”, “Position”, “Supervisor”, and “Department” and be in alphabetical order by supervisor’s last name. Person.lName Position.posTitle Person.lName Dept.deptName
4 Join Pathway EmpRec empID Person.pID Dept.deptID supID deptID posID Position.posID Because Person.pID makes 2 joins to  EmpRec, we’ll have to make a virtual copy of Person.
5 Expressions (32) List the last names of all current employees, their position titles,  the last names of their supervisors and the departments in which they work.    The view should have 4 columns named  “Supervisee”, “Position”, “Supervisor”, and “Department”  and be in alphabetical order by supervisor’s last name. WHERE EmpRec.endDate IS NULL SELECT  Person.lName AS Supervisee, Position.posTitle AS Position, Person.lName AS Supervisor, Dept.deptName AS Department ORDER BY Person.lName [Supervisor]
6 SQL Statement Combine the 3 steps and tweak the syntax to get the complete query. SELECT P.lName AS Supervisee, A.posTitle AS Position, B.LName AS Supervisor, 	D.deptName AS Department FROM Person P, Position A, Person B, Dept D, EmpRec E WHERE P.pID=E.empID AND B.pID=E.supID AND E.deptID=D.deptID AND 	E.posID=A.posID AND E.endDate IS NULL ORDER BY B.lName;
7 Another Example (33) List the designers’ and design assistants’ last names, the total numbers of hours each worked on each project, the project numbers, and the clients’ last names. The view should have 6 columns: “Designer”, “Design Assistant”, “Designer Hours”, “Design Assistant Hours”, “Project Number” and “Client”.
8 Another Example SELECT A.lName AS Designer, B.lName AS [Design Assistant],  	SUM(H.desHr) AS [Designer Hours],  	SUM(H.desAstHr) AS [Design Assistant Hours],  D.projNo AS [Project Number], C.lName AS Client FROM ProjDetail D, ProjHr H, Project P, Person A, Person B, Person C WHERE D.dtID=H.dtID AND P.projNo=D.projNo AND P.dID=A.pID AND  P.daID=B.pID AND P.cID=C.pID GROUP BY D.projNo, A.lName, B.lName, C.lName;

More Related Content

What's hot

Functions (Computer programming and utilization)
Functions (Computer programming and utilization)Functions (Computer programming and utilization)
Functions (Computer programming and utilization)Digvijaysinh Gohil
 
Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversionRashmiranja625
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluationJeeSa Sultana
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]ecko_disasterz
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackSoumen Santra
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsAfaq Mansoor Khan
 
CS151 Functions lecture
CS151 Functions lectureCS151 Functions lecture
CS151 Functions lectureRudy Martinez
 
Arrays and Pointers
Arrays and PointersArrays and Pointers
Arrays and PointersSimoniShah6
 
Pointers lesson 5 (double pointer, call by value, call_by_reference)
Pointers lesson 5 (double pointer, call by value, call_by_reference)Pointers lesson 5 (double pointer, call by value, call_by_reference)
Pointers lesson 5 (double pointer, call by value, call_by_reference)SetuMaheshwari1
 
Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...
Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...
Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...hwbloom119
 
Write declarations for each of the following variables: a. amounts is a...
Write declarations for each of the following variables:       a. amounts is a...Write declarations for each of the following variables:       a. amounts is a...
Write declarations for each of the following variables: a. amounts is a...licservernoida
 
[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...
[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...
[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...Giyeon Bang
 
[Question Paper] Advanced SQL (Revised Course) [January / 2014]
[Question Paper] Advanced SQL (Revised Course) [January / 2014][Question Paper] Advanced SQL (Revised Course) [January / 2014]
[Question Paper] Advanced SQL (Revised Course) [January / 2014]Mumbai B.Sc.IT Study
 

What's hot (20)

07.05 division
07.05 division07.05 division
07.05 division
 
Team 4
Team 4Team 4
Team 4
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
 
Infix to postfix
Infix to postfixInfix to postfix
Infix to postfix
 
Functions (Computer programming and utilization)
Functions (Computer programming and utilization)Functions (Computer programming and utilization)
Functions (Computer programming and utilization)
 
Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversion
 
Expression evaluation
Expression evaluationExpression evaluation
Expression evaluation
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
CS151 Functions lecture
CS151 Functions lectureCS151 Functions lecture
CS151 Functions lecture
 
Arrays and Pointers
Arrays and PointersArrays and Pointers
Arrays and Pointers
 
Pointers lesson 5 (double pointer, call by value, call_by_reference)
Pointers lesson 5 (double pointer, call by value, call_by_reference)Pointers lesson 5 (double pointer, call by value, call_by_reference)
Pointers lesson 5 (double pointer, call by value, call_by_reference)
 
Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...
Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...
Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...
 
Write declarations for each of the following variables: a. amounts is a...
Write declarations for each of the following variables:       a. amounts is a...Write declarations for each of the following variables:       a. amounts is a...
Write declarations for each of the following variables: a. amounts is a...
 
[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...
[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...
[C++ korea] effective modern c++ study item 5 prefer auto to explicit type de...
 
[Question Paper] Advanced SQL (Revised Course) [January / 2014]
[Question Paper] Advanced SQL (Revised Course) [January / 2014][Question Paper] Advanced SQL (Revised Course) [January / 2014]
[Question Paper] Advanced SQL (Revised Course) [January / 2014]
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 

Similar to Complex Joins

Rdbms class test ii sep 2019
Rdbms class test  ii sep 2019Rdbms class test  ii sep 2019
Rdbms class test ii sep 2019ARVIND SARDAR
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures topu93
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture topu93
 
DMS Question bank class test ii sep 2019
DMS Question bank class test ii sep 2019DMS Question bank class test ii sep 2019
DMS Question bank class test ii sep 2019ARVIND SARDAR
 
Question bank class test ii sep 2019
Question bank class test ii sep 2019Question bank class test ii sep 2019
Question bank class test ii sep 2019ARVIND SARDAR
 
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21chinthala Vijaya Kumar
 
Building Services With gRPC, Docker and Go
Building Services With gRPC, Docker and GoBuilding Services With gRPC, Docker and Go
Building Services With gRPC, Docker and GoMartin Kess
 
Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answersdebarghyamukherjee60
 
FDP-faculty deveopmemt program on python
FDP-faculty deveopmemt program on pythonFDP-faculty deveopmemt program on python
FDP-faculty deveopmemt program on pythonkannikadg
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
ABAP Programming Overview
ABAP Programming OverviewABAP Programming Overview
ABAP Programming Overviewsapdocs. info
 
Abapprogrammingoverview 090715081305-phpapp02
Abapprogrammingoverview 090715081305-phpapp02Abapprogrammingoverview 090715081305-phpapp02
Abapprogrammingoverview 090715081305-phpapp02wingsrai
 
Chapter 1abapprogrammingoverview-091205081953-phpapp01
Chapter 1abapprogrammingoverview-091205081953-phpapp01Chapter 1abapprogrammingoverview-091205081953-phpapp01
Chapter 1abapprogrammingoverview-091205081953-phpapp01tabish
 
chapter-1abapprogrammingoverview-091205081953-phpapp01
chapter-1abapprogrammingoverview-091205081953-phpapp01chapter-1abapprogrammingoverview-091205081953-phpapp01
chapter-1abapprogrammingoverview-091205081953-phpapp01tabish
 

Similar to Complex Joins (20)

Unit 2 web technologies
Unit 2 web technologiesUnit 2 web technologies
Unit 2 web technologies
 
Rdbms class test ii sep 2019
Rdbms class test  ii sep 2019Rdbms class test  ii sep 2019
Rdbms class test ii sep 2019
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture
 
DMS Question bank class test ii sep 2019
DMS Question bank class test ii sep 2019DMS Question bank class test ii sep 2019
DMS Question bank class test ii sep 2019
 
Question bank class test ii sep 2019
Question bank class test ii sep 2019Question bank class test ii sep 2019
Question bank class test ii sep 2019
 
C Programming Unit-4
C Programming Unit-4C Programming Unit-4
C Programming Unit-4
 
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
 
Building Services With gRPC, Docker and Go
Building Services With gRPC, Docker and GoBuilding Services With gRPC, Docker and Go
Building Services With gRPC, Docker and Go
 
C++
C++C++
C++
 
Structures
StructuresStructures
Structures
 
Class 12 computer sample paper with answers
Class 12 computer sample paper with answersClass 12 computer sample paper with answers
Class 12 computer sample paper with answers
 
FDP-faculty deveopmemt program on python
FDP-faculty deveopmemt program on pythonFDP-faculty deveopmemt program on python
FDP-faculty deveopmemt program on python
 
Amusing C#
Amusing C#Amusing C#
Amusing C#
 
C programming language
C programming languageC programming language
C programming language
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
 
ABAP Programming Overview
ABAP Programming OverviewABAP Programming Overview
ABAP Programming Overview
 
Abapprogrammingoverview 090715081305-phpapp02
Abapprogrammingoverview 090715081305-phpapp02Abapprogrammingoverview 090715081305-phpapp02
Abapprogrammingoverview 090715081305-phpapp02
 
Chapter 1abapprogrammingoverview-091205081953-phpapp01
Chapter 1abapprogrammingoverview-091205081953-phpapp01Chapter 1abapprogrammingoverview-091205081953-phpapp01
Chapter 1abapprogrammingoverview-091205081953-phpapp01
 
chapter-1abapprogrammingoverview-091205081953-phpapp01
chapter-1abapprogrammingoverview-091205081953-phpapp01chapter-1abapprogrammingoverview-091205081953-phpapp01
chapter-1abapprogrammingoverview-091205081953-phpapp01
 

Complex Joins

  • 2. 2 Strategy for Complex Joins (A) Identify which table columns contain the data needed. (B) Use the PK-FK pairs that make each join to plot the join “pathway”. Identify expressions to perform column and/or row operations needed and the clauses in which they belong.
  • 3. 3 Table Columns (32) List the last names of all current employees, their position titles, the last names of their supervisors and the departments in which they work. The view should have 4 columns named “Supervisee”, “Position”, “Supervisor”, and “Department” and be in alphabetical order by supervisor’s last name. Person.lName Position.posTitle Person.lName Dept.deptName
  • 4. 4 Join Pathway EmpRec empID Person.pID Dept.deptID supID deptID posID Position.posID Because Person.pID makes 2 joins to EmpRec, we’ll have to make a virtual copy of Person.
  • 5. 5 Expressions (32) List the last names of all current employees, their position titles, the last names of their supervisors and the departments in which they work. The view should have 4 columns named “Supervisee”, “Position”, “Supervisor”, and “Department” and be in alphabetical order by supervisor’s last name. WHERE EmpRec.endDate IS NULL SELECT Person.lName AS Supervisee, Position.posTitle AS Position, Person.lName AS Supervisor, Dept.deptName AS Department ORDER BY Person.lName [Supervisor]
  • 6. 6 SQL Statement Combine the 3 steps and tweak the syntax to get the complete query. SELECT P.lName AS Supervisee, A.posTitle AS Position, B.LName AS Supervisor, D.deptName AS Department FROM Person P, Position A, Person B, Dept D, EmpRec E WHERE P.pID=E.empID AND B.pID=E.supID AND E.deptID=D.deptID AND E.posID=A.posID AND E.endDate IS NULL ORDER BY B.lName;
  • 7. 7 Another Example (33) List the designers’ and design assistants’ last names, the total numbers of hours each worked on each project, the project numbers, and the clients’ last names. The view should have 6 columns: “Designer”, “Design Assistant”, “Designer Hours”, “Design Assistant Hours”, “Project Number” and “Client”.
  • 8. 8 Another Example SELECT A.lName AS Designer, B.lName AS [Design Assistant], SUM(H.desHr) AS [Designer Hours], SUM(H.desAstHr) AS [Design Assistant Hours], D.projNo AS [Project Number], C.lName AS Client FROM ProjDetail D, ProjHr H, Project P, Person A, Person B, Person C WHERE D.dtID=H.dtID AND P.projNo=D.projNo AND P.dID=A.pID AND P.daID=B.pID AND P.cID=C.pID GROUP BY D.projNo, A.lName, B.lName, C.lName;