Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins.

Slides:



Advertisements
Similar presentations
The Sales/Collection Business Process Accounts Receivable Query Join & Null to Zero (NZ) considerations 1.
Advertisements

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.
Table Relationships RDBM. Prof. Leighton2 Establishing Table Relationships RDBMS allow us to establish relationships among tables Have a primary key in.
4d. Structured Query Language – JOIN Operation Lingma Acheson Department of Computer and Information Science IUPUI CSCI N207 Data Analysis with Spreadsheets.
Computer Science & Engineering 2111 Introduction to Database Systems 1CSE 2111-Introduction to Database Systems.
A U Database Review Professor J. Alberto Espinosa ITEC 334 Fall 2010 Online (Business) Application Development.
SUNY Morrisville-Norwich Campus-Week 10 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
FIS 318/618: Financial Systems & Databases Queries Oakland University School of Business Administration Accounting and Finance Joe Callaghan.
1 CA202 Spreadsheet Application Working with Database Data Lecture # 14.
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.
Computer Science & Engineering 2111 CSE 2111 Lecture Querying a Database 1CSE 2111 Lecture- Querying a Database.
Computer Science & Engineering 2111 Introduction to Database Management Systems Relationships and Database Creation 1 CSE 2111 Introduction to Database.
Computer Science & Engineering 2111 CSE 2111 Lecture Basic Criteria in Queries 1CSE 2111 Lecture-Basic Criteria in Queries.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
1 Access Lesson 3 Creating Queries Microsoft Office 2010 Introductory Pasewark & Pasewark.
1 Access Lesson 3 Creating Queries Microsoft Office 2010 Introductory.
Copyright 2007, Paradigm Publishing Inc. BACKNEXTEND 3-1 LINKS TO OBJECTIVES Save a Filter as a Query Save a Filter as a Query Parameter Query Inner, Left,
CS&E 1111 AcQueries Writing Simple Queries in Access Displaying on specific data fields Filtering data using criteria Objectives: Learn how to use the.
CS&E 1111 AcQueries Querying in Access Sorting data Aggregating Data Performing Calculations Objectives: Learn how to use the Access Query Design Tool.
CS&E 1111 AcInnerJoins Inner Joins Objectives: Creating Queries with data from Multiple Tables Joining two tables using an Inner Join Referential Data.
Tutorial 8 Advanced Queries. Notes Switch to new database! Tutorial.08 folder Only Session 8.1 and 8.2.
SQL Unit 5 Aggregation, GROUP BY, and HAVING Kirk Scott 1.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
 Continue queries ◦ You completed two tutorials with step-by-step instructions for creating queries in MS Access. ◦ Now must apply knowledge and skills.
Microsoft Access 2010 Building and Using Queries.
IE 423 – Design of Decision Support Systems Database development – Relationships and Queries.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 9 1 Microsoft Office Access 2003 Tutorial 9 – Using Action Queries, and Defining Table Relationships.
Relationships and Advanced Query Concepts Using Multiple Tables Please use speaker notes for additional information!
Computer Science & Engineering 2111 Lecture 11 Querying a Database 1.
Access: Queries Ad-hoc Reporting Chapter T. Access Queries Queries Access Properties Sorting Selection Criteria Calculations.
1 Outline  What is a Primary Key?  AutoNumber primary keys  Single-field primary keys  Composite-field primary key  About Foreign Keys  Database.
 Agenda 2/20/13 o Review quiz, answer questions o Review database design exercises from 2/13 o Create relationships through “Lookup tables” o Discuss.
Computer Science & Engineering 2111 Lecture 10 Introduction to Database Management Systems 1.
® Microsoft Access 2010 Tutorial 9 Using Action Queries and Advanced Table Relationships.
Texas State Technical College DISCOVER! Inner Joins Let’s get together… yeah yeah yeah!
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making Chapter.
Computer Science & Engineering 2111 Querying a Database 1CSE 2111 Lecture- Querying a Database.
Computer Science & Engineering 2111 CSE 2111 Lecture Multiple and Compound Criteria in Queries 1 CSE 2111 Lecture-Multiple and Compound Criteria in Queries.
Tutorial 9 Using Action Queries and Advanced Table Relationships.
Exploring Microsoft Access Chapter 6 Many-to-Many Relationships: A More Complex System.
Pasewark & Pasewark 1 Access Lesson 3 Creating Queries Microsoft Office 2007: Introductory.
Computer Science & Engineering 2111 CSE 2111 Lecture NZ Function 1CSE 2111 NZ Function.
You can sort Access data so you can view records in the order you want to view them, and you can filter data so you only see the records you want to see.
IS201 Agenda: 09/19  Modify contents of the database.  Discuss queries: Turning data stored in a database into information for decision making.  Create.
Computer Science & Engineering 2111 Lecture 13 Outer Joins 1.
DAY 18: MICROSOFT ACCESS – CHAPTER 3 CONTD. Akhila Kondai October 21, 2013.
In this session, you will learn to: Query data by using joins Query data by using subqueries Objectives.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
Review Types of Relationship – there are in general three different types of relationships - One to One – where each record in one table can have not more.
Computer Science & Engineering 2111 Sorting in Queries 1CSE 2111 Lecture-Advanced Queries.
Computer Science & Engineering 2111 Database Objects 1 CSE 2111 Introduction to Database Management Systems.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Chapter 6 Many-to Many Relationship. Agenda AutoNumber Many-to-many relationship Cascaded updating and deleting Auto Lookup Parameter query Total query.
Computer Science & Engineering 2111 Inner Joins and Advanced Queries 1CSE 2111 Lecture-Advanced Queries.
Relational Databases Today we will look at: Different ways of searching a database Creating queries Aggregate Queries More complex queries involving different.
Writing Simple Queries in Access
Tables & Relationships
Basic Criteria in Queries
Querying in Access Objectives: Learn how to use the Access Query Design Tool manipulate data in Access: Sorting data Aggregating Data Performing Calculations.
Inner Joins Objectives: Creating Queries with data from Multiple Tables Joining two tables using an Inner Join Referential Data Integrity Cascade Update.
Objectives Create an action query to create a table
Hierarchy of Data in a Database
Basic Criteria in Queries
Introduction to Database Systems
Field Table Sort Show Criteria OR
Building and Using Queries
MS Access: Using Advanced Query Features
Access: Queries III Participation Project
Tutorial 9 Using Action Queries and Advanced Table Relationships
New Perspectives on Microsoft
Presentation transcript:

Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins

Inner Join between Client and Payments Notice that only records with matching values in the foreign key fields of the related tables are included in the resulting dynaset Resulting Dynaset PK FK CSE 2111 Lecture- Inner Vs. Outer Jioins2

Outer Join between Client and Payments Outer join relative to the Client table (the primary key side of the relationship) Resulting Dynaset CSE 2111 Lecture- Inner Vs. Outer Jioins3

Outer Join between Client and Payments Outer join relative to the Payments table (the many side of the relationship) Resulting Dynaset CSE 2111 Lecture- Inner Vs. Outer Jioins4

Valid and Invalid Relationships in Queries Many-One-Many  NOT VALID!! One-Many-One  OK! CSE 2111 Lecture-Many to One to Many Relationships in Queries 5

Many to One to Many Relationships Write a query to summarize by client, their total charges, total payments and balance due. List the Client ID, First Name, Last Name, total charges, total payments, and balance. CSE 2111 Lecture-Many to One to Many Relationships in Queries 6

Running a Query with Client, Charges and Payments: The Design View CSE 2111 Lecture-Many to One to Many Relationships in Queries 7

Client Charges Payments Resulting Dynaset First-what should the results look like? CSE 2111 Lecture-Many to One to Many Relationships in Queries 8

What we actually get Should Nancy have total charges of $750 and total payments of $700? Now let’s see what really happens….. What we WANT 9 What we GET CSE 2111 Lecture-Many to One to Many Relationships in Queries

So what happened? Clients Charges Payments Intermediate Dynaset 1 Intermediate Dynaset 2 Final Dynaset Aggregate functions applied/Expressions calculated CSE 2111 Lecture-Many to One to Many Relationships in Queries 10

Charges Client Resulting Intermediate Dynaset 1 (Partial View) 11 CSE 2111 Lecture-Many to One to Many Relationships in Queries

Intermediate Dynaset 1Payments Resulting Intermediate Dynaset 2 (Partial View) 12 $ CSE 2111 Lecture-Many to One to Many Relationships in Queries

Aggregate functions & expressions are applied last: Final Dynaset Resulting Intermediate Dynaset 2 CSE 2111 Lecture-Many to One to Many Relationships in Queries 13

1 ∞ Client Charges 1 Payments Client ∞ Split up the relationship! 14 So what do we do? SUMMARIZE CHARGES BY CLIENT SUMMARIZE PAYMENTS BY CLIENT CSE 2111 Lecture-Many to One to Many Relationships in Queries

PaymentsByClient Tables: Client, Payments Join On: ClientIDJoin Type: Outer Field:ClientIDFirstNameLastNameAmount Table:Client Payments Total:Group By Sum Sort: Show:XXXX Criteria: Or: 15 CSE 2111 Lecture-Many to One to Many Relationships in Queries

ChargesByClient Tables: Client, Charges Join On: ClientID Join Type: Outer Field:ClientIDAmount Table:ClientCharges Total:Group BySum Sort: Show:XXXX Criteria: Or: 16 CSE 2111 Lecture-Many to One to Many Relationships in Queries

Notice that each client is listed exactly once in both queries. 1 ChargesByClient PaymentsByClient 1 Now we can put the relationship back together! Join on ClientID PaymentsByClientChargesByClient CSE 2111 Lecture-Many to One to Many Relationships in Queries 17

BalanceDue Tables: PaymentsByClient,ChargesByClient Join On: ClientIDJoin Type: Inner Field: ClientIDFirstNameLastNameSumOfAmount Balance* Table: PaymentsBy Client ChargesBy Client Total: Sort: Show: XXXXXX Balance: [ChargesByClient]![SumOfAmount] – [PaymentsByClient]![SumOfAmount] Now put the two summaries together & calculate the balance due… 18 CSE 2111 Lecture-Many to One to Many Relationships in Queries

Final Dynaset Karen Day was charged $100 but hasn’t made a payment. Her balance should be $100 - $0 = $100, but it’s blank. Why? CSE 2111 Lecture-Many to One to Many Relationships in Queries 19

Many-One-Many  NOT VALID!! One-Many-One  OK! 20 Using 3 or more tables in a query CSE 2111 Lecture- One to Many to One Relationships in Queries

Using 3 or more tables in a query Write a query to list the Client ID, first name, last name, and the Method Type, for all Clients. One-Many-One Relationship 21 CSE 2111 Lecture- One to Many to One Relationships in Queries

What we get Now let’s see what really happens….. What we WANT CSE 2111 Lecture- One to Many to One Relationships in Queries 22

ClientPayments Intermediate Dynaset 1 23 CSE 2111 Lecture- One to Many to One Relationships in Queries

Intermediate Dynaset 1 PaymentMethod Final Dynaset 24 CSE 2111 Lecture- One to Many to One Relationships in Queries

ClientPayments Let’s take a closer look at the PaymentsByClient Query….in an outer join with respect to Clients, when a record from Clients doesn’t have any matching records in Payments, it’s included in the results, but the fields that would have come from Payments are NULL. CSE NZ Function25

Access doesn’t know what $100 – NULL is, so it returns NULL as the result. But we know that in this case, NULL should be treated like zero – can we help Access out? CSE NZ Function26

NZ Function Syntax: Nz(variant, value_if_null) If this argument evaluates to NULL…. Return this value If the variant argument does NOT evaluate to NULL, Nz will return whatever the variant argument does evaluate to. CSE NZ Function27

BalanceDue Tables: PaymentsByClient,ChargesByClient Join On: ClientIDJoin Type: Inner Field: ClientIDFirstNameLastNameSumOfAmount Balance* Table: PaymentsBy Client ChargesBy Client Total: Sort: Show: XXXXXX Balance: Nz([Charges]![SumOfAmount],0) – Nz([Payments]![SumOfAmount],0) Balance Due with the Nz function….. CSE NZ Function28

Finally! CSE NZ Function29