SlideShare a Scribd company logo
ComplexInner Joins I
2Strategy 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.
3Table 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.lNamePosition.posTitlePerson.lNameDept.deptName
4Join PathwayEmpRecempIDPerson.pIDDept.deptIDsupIDdeptIDposIDPosition.posIDBecause Person.pID makes 2 joins to  EmpRec, we’ll have to make a virtual copy of Person.
5Expressions(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 NULLSELECT  Person.lName AS Supervisee, Position.posTitle AS Position, Person.lName AS Supervisor, Dept.deptName AS DepartmentORDER BY Person.lName [Supervisor]
6SQL StatementCombine 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 DepartmentFROM Person P, Position A, Person B, Dept D, EmpRec EWHERE P.pID=E.empID AND B.pID=E.supID AND E.deptID=D.deptID AND 	E.posID=A.posID AND E.endDate IS NULLORDER BY B.lName;
7Another 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”.
8Another ExampleSELECT 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 ClientFROM ProjDetail D, ProjHr H, Project P, Person A, Person B, Person CWHERE D.dtID=H.dtID AND P.projNo=D.projNo AND P.dID=A.pID AND P.daID=B.pID AND P.cID=C.pIDGROUP BY D.projNo, A.lName, B.lName, C.lName;

More Related Content

PDF
Infix to Prefix (Conversion, Evaluation, Code)
PPTX
Functions in c++,
PPTX
Evaluation of postfix expression
PDF
computer notes - Evaluating postfix expressions
PPTX
Functions in c++
PPTX
Function Pointer in C
PDF
[計一] Basic r programming final0918
Infix to Prefix (Conversion, Evaluation, Code)
Functions in c++,
Evaluation of postfix expression
computer notes - Evaluating postfix expressions
Functions in c++
Function Pointer in C
[計一] Basic r programming final0918

What's hot (20)

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

Similar to Complex inner joins (20)

PDF
0808.pdf
PPT
Introduction to-sql
PPTX
Data Retrival
PDF
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
PDF
Priyanka Bhatia.BCA Final year 2015
PPTX
Day-2 SQL Theory_V1.pptx
PDF
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
ODP
BIS05 Introduction to SQL
PPTX
SentricWorkforce Query Builder: Joins and Tables
PDF
Nikhil Khandelwal BCA 3rd Year
PPTX
Sql intro
PPTX
PDF
Simran kaur,BCA Final Year 2015
PDF
Vijay Kumar
PPTX
More Complex SQL and Concurrency ControlModule 4.pptx
PPTX
Data Manipulation Language.pptx
DOCX
Sql Queries
PDF
SQL command for daily use ddl dml dcl dql
0808.pdf
Introduction to-sql
Data Retrival
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
Priyanka Bhatia.BCA Final year 2015
Day-2 SQL Theory_V1.pptx
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
BIS05 Introduction to SQL
SentricWorkforce Query Builder: Joins and Tables
Nikhil Khandelwal BCA 3rd Year
Sql intro
Simran kaur,BCA Final Year 2015
Vijay Kumar
More Complex SQL and Concurrency ControlModule 4.pptx
Data Manipulation Language.pptx
Sql Queries
SQL command for daily use ddl dml dcl dql
Ad

Complex inner joins

  • 2. 2Strategy 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. 3Table 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.lNamePosition.posTitlePerson.lNameDept.deptName
  • 4. 4Join PathwayEmpRecempIDPerson.pIDDept.deptIDsupIDdeptIDposIDPosition.posIDBecause Person.pID makes 2 joins to EmpRec, we’ll have to make a virtual copy of Person.
  • 5. 5Expressions(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 NULLSELECT Person.lName AS Supervisee, Position.posTitle AS Position, Person.lName AS Supervisor, Dept.deptName AS DepartmentORDER BY Person.lName [Supervisor]
  • 6. 6SQL StatementCombine 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 DepartmentFROM Person P, Position A, Person B, Dept D, EmpRec EWHERE P.pID=E.empID AND B.pID=E.supID AND E.deptID=D.deptID AND E.posID=A.posID AND E.endDate IS NULLORDER BY B.lName;
  • 7. 7Another 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. 8Another ExampleSELECT 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 ClientFROM ProjDetail D, ProjHr H, Project P, Person A, Person B, Person CWHERE D.dtID=H.dtID AND P.projNo=D.projNo AND P.dID=A.pID AND P.daID=B.pID AND P.cID=C.pIDGROUP BY D.projNo, A.lName, B.lName, C.lName;