computer science & engineering 2111 outer joins 1cse 2111 lecture- inner vs. outer jioins
TRANSCRIPT
![Page 1: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/1.jpg)
1
Computer Science & Engineering 2111
Computer Science & Engineering 2111
Outer Joins
CSE 2111 Lecture- Inner Vs. Outer Jioins
![Page 2: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/2.jpg)
CSE 2111 Lecture- Inner Vs. Outer Jioins
2
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 DynasetPK FK
![Page 3: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/3.jpg)
CSE 2111 Lecture- Inner Vs. Outer Jioins
3
Outer Join between Client and PaymentsOuter join relative to the Client table (the primary key side of the relationship)
Resulting Dynaset
![Page 4: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/4.jpg)
CSE 2111 Lecture- Inner Vs. Outer Jioins
4
Outer Join between Client and PaymentsOuter join relative to the Payments table (the many side of the relationship)
Resulting Dynaset
![Page 5: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/5.jpg)
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
![Page 6: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/6.jpg)
Many to One to Many RelationshipsWrite 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
![Page 7: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/7.jpg)
Running a Query with Client, Charges and Payments: The Design View
CSE 2111 Lecture-Many to One to Many Relationships in Queries 7
![Page 8: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/8.jpg)
Client
Charges
Payments
Resulting DynasetFirst-what should the results look like?
CSE 2111 Lecture-Many to One to Many Relationships in Queries 8
![Page 9: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/9.jpg)
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
![Page 10: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/10.jpg)
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
![Page 11: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/11.jpg)
Charges
Client
Resulting Intermediate Dynaset 1 (Partial View)
11CSE 2111 Lecture-Many to One to Many Relationships in Queries
![Page 12: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/12.jpg)
Intermediate Dynaset 1 Payments
Resulting Intermediate Dynaset 2 (Partial View)
12
$100.00
CSE 2111 Lecture-Many to One to Many Relationships in Queries
![Page 13: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/13.jpg)
Aggregate functions & expressions are applied last:
Final Dynaset
Resulting Intermediate Dynaset 2
CSE 2111 Lecture-Many to One to Many Relationships in Queries 13
![Page 14: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/14.jpg)
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
![Page 15: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/15.jpg)
PaymentsByClient Tables: Client, Payments
Join On: ClientID Join Type: Outer
Field: ClientID FirstName LastName Amount
Table: Client Client Client Payments
Total: Group By Group By Group By Sum
Sort:
Show: X X X X
Criteria:
Or:
15CSE 2111 Lecture-Many to One to Many Relationships in Queries
![Page 16: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/16.jpg)
ChargesByClient Tables: Client, Charges
Join On: ClientID Join Type: OuterField: ClientID Amount
Table: Client Charges
Total: Group By Sum
Sort:
Show: X X X X
Criteria:
Or:
16CSE 2111 Lecture-Many to One to Many Relationships in Queries
![Page 17: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/17.jpg)
Notice that each client is listed exactly once in both queries.
1ChargesByClientPaymentsByClient
1
Now we can put the relationship back together!
Join on ClientID
PaymentsByClient ChargesByClient
CSE 2111 Lecture-Many to One to Many Relationships in Queries 17
![Page 18: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/18.jpg)
BalanceDue Tables: PaymentsByClient,ChargesByClientJoin On: ClientID Join Type: Inner
Field: ClientID FirstName LastName SumOfAmount SumOfAmount Balance*
Table: PaymentsByClient
PaymentsByClient
PaymentsByClient
PaymentsByClient
ChargesByClient
Total:
Sort:
Show: X X X X X X
Balance: [ChargesByClient]![SumOfAmount] – [PaymentsByClient]![SumOfAmount]
Now put the two summaries together & calculate the balance due…
18CSE 2111 Lecture-Many to One to Many Relationships in Queries
![Page 19: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/19.jpg)
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
![Page 20: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/20.jpg)
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
![Page 21: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/21.jpg)
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
21CSE 2111 Lecture- One to Many to One Relationships in Queries
![Page 22: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/22.jpg)
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
![Page 23: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/23.jpg)
Client Payments
Intermediate Dynaset 1
23CSE 2111 Lecture- One to Many to One Relationships in Queries
![Page 24: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/24.jpg)
Intermediate Dynaset 1
PaymentMethod
Final Dynaset
24CSE 2111 Lecture- One to Many to One Relationships in Queries
![Page 25: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/25.jpg)
Client Payments
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 2111- NZ Function 25
![Page 26: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/26.jpg)
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 2111- NZ Function 26
![Page 27: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/27.jpg)
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 2111- NZ Function 27
![Page 28: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/28.jpg)
BalanceDue Tables: PaymentsByClient,ChargesByClientJoin On: ClientID Join Type: Inner
Field: ClientID FirstName LastName SumOfAmount SumOfAmount Balance*
Table: PaymentsByClient
PaymentsByClient
PaymentsByClient
PaymentsByClient
ChargesByClient
Total:
Sort:
Show: X X X X X X
Balance: Nz([Charges]![SumOfAmount],0) – Nz([Payments]![SumOfAmount],0)
Balance Due with the Nz function…..
CSE 2111- NZ Function 28
![Page 29: Computer Science & Engineering 2111 Outer Joins 1CSE 2111 Lecture- Inner Vs. Outer Jioins](https://reader036.vdocuments.site/reader036/viewer/2022062309/5697bf751a28abf838c80755/html5/thumbnails/29.jpg)
Finally!
CSE 2111- NZ Function 29