IFS180 Intro. to Data Management Chapter 9 – Outer Joins.

Slides:



Advertisements
Similar presentations
Advanced SQL (part 1) CS263 Lecture 7.
Advertisements

© Abdou Illia MIS Spring 2014
Sometimes you need to use data from more than one table. In example1, the report displays data from two separate tables. Employee IDs exist in the EMPLOYEES.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Joins and Sub-queries in SQL.
Chapter 4 Joining Multiple Tables
A Guide to SQL, Seventh Edition. Objectives Use joins to retrieve data from more than one table Use the IN and EXISTS operators to query multiple tables.
Relational Database Operators
Chapter 7 © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition Jeffrey A. Hoffer, V. Ramesh, Heikki Topi.
MULTIPLE-TABLE QUERIES
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
The Relational Database Model
Instructor: Craig Duckett CASE, ORDER BY, GROUP BY, HAVING, Subqueries
Modeling the Data: Conceptual and Logical Data Modeling
Chapter 2 The Relational Database Model
Introduction to Oracle9i: SQL1 Basic SQL SELECT Statements.
The Relational Database Model
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
LIS 557 Database Design and Management William Voon Michael Cole Spring '04.
The Relational Database Model. 2 Objectives How relational database model takes a logical view of data Understand how the relational model’s basic components.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Inner join, self join and Outer join Sen Zhang. Joining data together is one of the most significant strengths of a relational database. A join is a query.
The Relational Database Model
The Relational Database Model
Concepts of Database Management, Fifth Edition
Chapter 4 The Relational Model.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Chapter 9 Joining Data from Multiple Tables
A Guide to MySQL 5. 2 Objectives Use joins to retrieve data from more than one table Use the IN and EXISTS operators to query multiple tables Use a subquery.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
CSC271 Database Systems Lecture # 12. Summary: Previous Lecture  Row selection using WHERE clause  WHERE clause and search conditions  Sorting results.
1 Intro to JOINs SQL INNER JOIN SQL OUTER JOIN SQL FULL JOIN SQL CROSS JOIN Intro to VIEWs Simple VIEWs Considerations about VIEWs VIEWs as filters ALTER.
The Relational Database Model
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making Chapter.
Relational Databases.  In week 1 we looked at the concept of a key, the primary key is a column/attribute that uniquely identifies the rest of the data.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Data Driven Designs 99% of enterprise applications operate on database data or at least interface databases. Most common DBMS are Microsoft SQL Server,
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
SQL LANGUAGE and Relational Data Model TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Chapter 12 Subqueries and Merge Statements
Views, Algebra Temporary Tables. Definition of a view A view is a virtual table which does not physically hold data but instead acts like a window into.
A Guide to SQL, Eighth Edition Chapter Five Multiple-Table Queries.
IFS180 Intro. to Data Management Chapter 13 – Grouping Data.
Query Processing – Implementing Set Operations and Joins Chap. 19.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
McGraw-Hill/Irwin Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Modeling the Data: Conceptual and Logical Data Modeling.
Thinking in Sets and SQL Query Logical Processing.
Week 2 Lecture The Relational Database Model Samuel ConnSamuel Conn, Faculty Suggestions for using the Lecture Slides.
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
CSC314 DAY 9 Intermediate SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall USING AND DEFINING VIEWS  Views provide users controlled.
IFS180 Intro. to Data Management Chapter 10 - Unions.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
The Relational Database Model
Chapter 12 Subqueries and MERGE Oracle 10g: SQL
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Database Systems: Design, Implementation, and Management Tenth Edition
David M. Kroenke and David J
Chapter 3 The Relational Database Model
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Chapter 8 Advanced SQL.
DCT 2053 DATABASE CONCEPT Chapter 2.2 CONTINUE
Database Systems: Design, Implementation, and Management Tenth Edition
SQL set operators and modifiers.
Relational Database Operators
Presentation transcript:

IFS180 Intro. to Data Management Chapter 9 – Outer Joins

Review of Inner Join Function Purpose of inner join is to create a result set of related or matching rows between tables Challenging when you don’t know the data set, hence you need some form of relationship diagram (ERD) Two tables are relatively straight forward From table name inner join table name on search criteria Embedded select statement valid any place a table name can be used

Review of Inner Join Embedded select statements good when: Result set is subset of columns filtered on a particular characteristic associated with column in the result set (example) Need to calculate / accumulate values from one table to be used with calculations on columns from another table (due to the normalized form rule of no accumulated values) No rule of thumb other than performance issues (however, you will find they are also common in where clause)

Review of Inner Join Three or more tables Table one and two form a logical table Logical table is joined to table 3 forming one logical table Logical table joins are repeated until number of left parenthesis equal number of right parenthesis (((( …. )))) Example

Difference in Set Theory Unlike Intersection set theory (commonality) difference in set theory seeks difference among sets (Again) to compare sets, all member in the sets must have the same number and type of attributes Difference between set one and set two are those members (of set one) that have different attributes from set two Difference between set two and set one are those members (of set two) that have different attributes from set one

Difference in Set Theory Identification BlackAllisterSeattleWA166 HallmarkJoeWoodinWA157 EhrlichZacharySeattleWA143 RojalesJoeTacomaWA166 PattersonRachelAuburnWA157 RiserBrianSeattleWA152 HindmanRickDuvallWA145 MankenDonBellevueWA157 RojalesJoeTacomaWA166 JonesFredSeattleWA158 First NameLast NameCityStAvg Primary Key Tuesday League Primary Key Monday League

Difference Set Theory Intersection use to find equality between one or more data sets and inequality Members in Seattle Members Names not Joe Average > 160 Seattle and not Joe Seattle, not Joe, > 160

Difference Set theory difference implemented in SQL standard with the (Outer) JOIN operation Imperative to understand the relationships between the tables Purpose of the Outer Join is to return rows that match your criteria and to include unmatched rows from either one or both of the sets you want to link

Outer Join Generally, dealing with one-to-many table relationship. Parent / Child relationship Where Parent in one table may have zero or more “children” rows Where the zero or many “children” rows have one parent row When selecting rows with outer join, interested in all rows from one table and any matching rows from a second table Null will be used frequently

Left Outer Join Basic syntax: From table name LEFT OUTER JOIN table name ON Cartesian Product is created (logical combination of all rows in both tables) The search criteria of the ON statement is applied to select desired rows. Remember to fully qualify column names

Left Outer Join First table named is the “left” table Used when all rows in “left” / first table are required and any matching rows from the second table SQL default is an inner join, therefore you must declare left outer join Critical portion of the (any) join statement is the ON (or using) statement where the actual selection occurs

Join with Embedded Select Statements Working with more than two table Substitute a complete select statement for a table name Requires a correlation name assigned to the embedded select (for reference purposes) Embedded select may include all clauses except order by clause In essence, query within a query and you must return any column and linking values for joins

Embedding Joins within Joins Use with caution. Potential Performance issues exit Anywhere a table name can be specified, a join clause surrounded with parentheses may be used Just like embedded inner joins, a “logical” table is created on the two joined tables

Other Join Types Full Outer Join Both a left and right outer join Null values are established when no matching values exist on the left or right side Union Join Full outer join with matches omitted. Uses?

Outer join uses Finding missing values What products have never been ordered List entertainers who have never been booked Display students who have never withdrawn from a class List ingredients not used in any recipe

Outer Join Uses Finding partially matched information List all products and the dates for any order List all bowlers and games they bowled over 160.