U:/msu/course/cse/103 Day 08, Slide 1 CSE 103 Students: –Review days 7 and 8 if you need to go over relationships and INNER.

Slides:



Advertisements
Similar presentations
Database Relationships in Access As you recall, the data in a database is stored in tables. In a relational database like Access, you can have multiple.
Advertisements

Build a database I: Design tables for a new Access database
Microsoft® Access® 2010 Training
Chapter 4 Joining Multiple Tables
Chapter 7 © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database Management 11 th Edition Jeffrey A. Hoffer, V. Ramesh, Heikki Topi.
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
Introduction to Oracle9i: SQL1 Basic SQL SELECT Statements.
1 CSE Students: Please do not log in yet. Check-in with Brian in the back. Review Days 3 and 4 in the book. Others: Please save your work and logout.
U:/msu/course/cse/103 Day 16, Slide 1 CSE 103 Day 16 Students: Read Day 10. If you are logged in, add records to your contacts.
U:/msu/course/cse/103 Day 23, Slide 1 Review of Day 22 What query did you use to search for an actor by name? –Return matches.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 4: Joins Part II.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 2: Single-Table Selections.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
How to Check Books In and Out (as well as other library materials) A tutorial for librarians who use Agent VERSO.
Using Relational Databases and SQL Department of Computer Science California State University, Los Angeles Lecture 8: Subqueries.
U:/msu/course/cse/103 Day 25, Slide 1 Back-up PHP Files If you have not yet passed the 3.0 BT, make back-up copies of ALL.
ACCESS CHAPTER 1. OBJECTIVES Tables Queries Forms Reports Primary and Foreign Keys Relationship.
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,
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
U:/msu/course/cse/103 Day 10, Slide 1 CSE 103 Students: Your BTs have been graded. See Erica or Jo with questions or stay.
U:/msu/course/cse/103 Day 04, Slide 1 CSE students: Do not log in yet. Computers are SLOW today! Review days 13.
McGraw-Hill Technology Education © 2004 by the McGraw-Hill Companies, Inc. All rights reserved. Office Access 2003 Lab 3 Analyzing Data and Creating Reports.
Analyzing Data For Effective Decision Making Chapter 3.
Lecture 2 of Advanced Databases Advanced SQL Instructor: Mr.Ahmed Al Astal.
Chapter 9 Joining Data from Multiple Tables
XP New Perspectives on Microsoft Office Access 2003 Tutorial 9 1 Microsoft Office Access 2003 Tutorial 9 – Using Action Queries, and Defining Table Relationships.
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.
U:/msu/course/cse/103 Day 07, Slide 1 Day 15 Review What datatype would be an appropriate choice for: –A cell phone number.
U:/msu/course/cse/103 Day 06, Slide 1 CSE students: Do not log in yet. Review Day 6 in your textbook. Think about.
JOI/1 Data Manipulation - Joins Objectives –To learn how to join several tables together to produce output Contents –Extending a Select to retrieve data.
® Microsoft Access 2010 Tutorial 9 Using Action Queries and Advanced Table Relationships.
M1G Introduction to Database Development 5. Doing more with queries.
Day 13, Slide 1 U:/msu/course/cse/103 CSE 103 Students: Review INNER and OUTER JOINs, Subqueries. Others: Please save your.
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
1 CSE 103 Section 002: M/W 10:20am-12:10pm 216 Berkey Hall Section 004: T/R 10:20am-12:10pm 1210 Anthony Hall.
Tutorial 9 Using Action Queries and Advanced Table Relationships.
Using Relational Databases and SQL Department of Computer Science California State University, Los Angeles Lecture 4: Joins Part II.
U:/msu/course/cse/103 Day 18, Slide 1 CSE 103 Day 18 If you are not enrolled in CSE 103, please save and log out by 10:10.
U:/msu/course/cse/103 Day 03, Slide 1 CSE 103 Day 15: Database Design Students: –Read Day 2 in your textbook –Your BT feedback.
U:/msu/course/cse/103 Day 21, Slide 1 CSE 103 Makeups –If you didn’t take one over the weekend, take one TUESDAY or WEDNESDAY!
A Guide to SQL, Eighth Edition Chapter Five Multiple-Table Queries.
U:/msu/course/cse/103 Day 12, Slide 1 CSE 103 Students: Read Day 18 and learn about subqueries Others: Please save your.
# 1# 1 QueriesQueries How do we ask questions of the data? What is SELECT? What is FROM? What is WHERE? What is a calculated field? Spring 2010 CS105.
Lesson 4: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Set query.
U:/msu/course/cse/103 Day 08, Slide 1 Debrief Homework What problems arose in trying to import the data from Classical_Music.xls?
Homework 2 Hints. General Tips Remember what FORM view you are in! – Design, form, and layout view TABLE views include: – Design and Datasheet view.
® Microsoft Access 2010 Tutorial 9 Using Action Queries and Advanced Table Relationships.
Day 5 - More Complexity With Queries Explanation of JOIN & Examples Explanation of JOIN & Examples Explanation & Examples of Aggregation Explanation &
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
CS 122: Lecture 3 Joins (Part 1) Tarik Booker CS 122 California State University, Los Angeles October 7, 2014.
 MySQL  DDL ◦ Create ◦ Alter  DML ◦ Insert ◦ Select ◦ Update ◦ Delete  DDL(again) ◦ Drop ◦ Truncate.
Copyright © 2016 Pearson Education, Inc. CHAPTER 7: ADVANCED SQL (PART I) Modern Database Management 12 th Edition Jeff Hoffer, Ramesh Venkataraman, Heikki.
Day 22, Slide 1 CSE 103 Day 22 Non-students: Please logout by 10:12. Students:
Tarik Booker CS 122. What we will cover… Tables (review) SELECT statement DISTINCT, Calculated Columns FROM Single tables (for now…) WHERE Date clauses,
CSC314 DAY 9 Intermediate SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall USING AND DEFINING VIEWS  Views provide users controlled.
SQL – join.
CSE 103 Day 15: Database Design
SQL – Subqueries.
Writing Basic SQL SELECT Statements
David M. Kroenke and David J
CSE Students: Please do not log in yet.
Debrief Homework Import data from the text file CanadianUniversities06.txt into a temporary table. What is the primary key for this table? Construct an.
Tutorial 9 Using Action Queries and Advanced Table Relationships
Presentation transcript:

U:/msu/course/cse/103 Day 08, Slide 1 CSE 103 Students: –Review days 7 and 8 if you need to go over relationships and INNER JOINs again Can also review Day 7 Notes on web page –Read Day 11 for INNER vs. OUTER JOIN –Today we will continue with INNER JOINs and ultimately move on to OUTER JOIN as well Others: –Please save your work and log out ASAP.

U:/msu/course/cse/103 Day 08, Slide 2 Homework Debrief What are the three types of relationships and what are some examples of each from our databases? When does the JOIN keyword need to appear in an SQL statement? What are the different types of JOINS?

U:/msu/course/cse/103 Day 08, Slide 3 INNER JOINs Inner Join – combines records from two tables whenever there are matching values in a matched field –e.g., SELECT MovieID, Role FROM tbl_Roles INNER JOIN tbl_People ON ActorID = PersonID WHERE FirstName = "Matt" AND LastName = "Damon" –With multiple tables, duplicate fieldnames can occur. Use tbl_name.fieldname to clarify. NULL never matches

U:/msu/course/cse/103 Day 08, Slide 4 Homework problem What type of Movie was more common in 2004, ACT (Action) or COM (Comedy)? –Use two queries What tables do we need? –How are the tables related? –How do we write the FROM line? What other restrictions do we need? –How do we enforce these? How can we easily write the second query once the first is done?

U:/msu/course/cse/103 Day 08, Slide 5 Multiple-table queries in Design View In Design view for a query, ADD all the tables you will need Scroll each table's list of fields so the related fields are visible Drag one field onto the other (direction doesn't matter) Tables are now related via INNER JOIN Setup rest of query as before

U:/msu/course/cse/103 Day 08, Slide 6 Multiple-table queries in Design View: Exercise Using the music-day08 database (copied to your P:) construct the following queries: –List album titles and years with their label name [42] (qry_day08_albums_with_labels) –List the digital tracks with their track title, duration, and digital filesize [362] (qry_day08_digital_tracksizes) –List the tracks in the database (track number and title) with the name of their secondary artist [9] (qry_day08_secondary_artists)

U:/msu/course/cse/103 Day 08, Slide 7 INNER JOINs and table aliases What SQL Keyword is used for aliases (remember calculated fields)? Same idea, only now rename tables to make JOINs easier –Also enables using same table twice, as in self-join Use table alias throughout ENTIRE query: SELECT MovieTitle, r.MovieID, Role FROM tbl_Roles AS r INNER JOIN tbl_Movies AS m ON r.MovieID = m.MovieID WHERE MovieTitle = "Blues Brothers, The"

U:/msu/course/cse/103 Day 08, Slide 8 Pencil and Paper Exercise on Relation Tables Does it matter which tables we join first? What does the shaded area in the upper left-hand corner of the worksheet represent? Which two tables should be joined next to complete the relational JOIN table? How many rows does the resulting JOIN have?

U:/msu/course/cse/103 Day 08, Slide 9 Relationships in Movies Work in your groups to identify relationships in the movies database –For each pair of tables, choose 1:1, 1:N, N:M, or not related –Look at primary keys; find where they're used as foreign keys –Use common sense… think "Does 1 X have many Y?" But always check that the keys support this idea!

U:/msu/course/cse/103 Day 08, Slide 10 Multiple-table Queries in Movies –Create a list of all the movies (titles and years) in which Robert Redford has appeared. [62] –Create a list of all the directors who have made “Frankenstein” movies, to include the title, year, and director’s name. [68] –Create a list of everyone who appeared in any movie made after 1990 who has since died [1961 with duplicates] How can we remove duplicates? [595]

U:/msu/course/cse/103 Day 08, Slide 11 Matching partial data: SQL OUTER JOIN…ON Outer Join –Useful with relationships where not all X have some property Y 1:1s always have this: not all tracks have a digital track; not all movies have a rating Some 1:Ns/M:Ns – not every person has an acting role; not every album has a label (because our data is incomplete) LEFT OUTER JOIN – combines records from two tables, but shows all records from the left table even if there are no matches with the right table e.g., All tracks, showing secondary artists where present: …tbl_Tracks LEFT JOIN tbl_Artists ON [Secondary Artist] = ArtistID Right Outer Join – (likewise … right table ….) Fields in the unmatched table(s) are set to NULL

U:/msu/course/cse/103 Day 08, Slide 12 OUTER JOIN in Design View Setup the query as if you were using an INNER JOIN Double-click the relationship to change –Look at options: first always corresponds to INNER JOIN (matched records only) –Second and third correspond to LEFT and RIGHT, but read carefully to see which table you want to include ALL from Access will use LEFT or RIGHT correctly; you don't have to know which is which

U:/msu/course/cse/103 Day 08, Slide 13 Music-day08 Multi-table queries Construct a list of Tracks with Track and Album Titles, arranged by album [376] qry_day08_titles Use that as a starting point for the next few queries (start over each time): –Add secondary artist names, still listing all tracks (qry_day08_titles_with_2 nd _artist) –Add labels for all tracks, even if unknown (qry_day08_titles_with_labels) –Find tracks that have no digital tracks [14] (qry_day08_titles_missing_digitracks)

U:/msu/course/cse/103 Day 08, Slide 14 Bridge Task 1.5 Everyone should come –Get next BT not passed, either 1.0 or 1.5 Primarily on material from Days 6-8 –Action queries and importing, append –INNER and OUTER JOIN in SQL and Access –Be sure homework is all done Have copies of databases we used in class and homework: –music_demo, music-day08, colleges&universities Bring photo ID!

U:/msu/course/cse/103 Day 08, Slide 15 Homework Prepare for BT 1.5 –Make sure that you have completed ALL imports into the various databases! Practice queries… ask questions like "Who starred in Action movies in 2003?" and write queries to solve them Reread textbook chapters 6-8 and 11 Understand relationships in our databases so you can join tables correctly