Some relationship types Using the Builder2 schema.

Slides:



Advertisements
Similar presentations
Multiple Table Queries
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.
Chapter 4 Joining Multiple Tables
CSC271 Database Systems Lecture # 13. Summary: Previous Lecture  Grouping through GROUP BY clause  Restricted groupings  Subqueries  Multi-Table queries.
Database Management Systems & Programming Faculty of Information & Media Studies Summer 2000 LIS Week 6 Structured Query Language.
1 Minggu 4, Pertemuan 8 SQL: Data Manipulation (Cont.) Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Populating and Querying tables Insert and mostly View (DML)
PL/SQL Continued. So far… Anonymous blocks Procedures Have you tried… –Downloading and running the dispcust.sql sample from your web page? –Writing your.
Sample queries Practice in using Oracle SQL (1 of 2)
1 Databases Semester 2 Week 1 Lab 2 The Delete, grant, revoke and Select Statements.
Tutorial 2 DT228/3 Database Technology. Joe’s Yard Take the following documents: –The script as prepared –The docket –The diary in the yard –The list.
Specification for Write Docket From Joe’s Yard. Requirements We’ve seen the docket and know it needs to be filled. To fill the docket, we need to: –Generate.
Chapter 6 SQL: Data Manipulation Cont’d. 2 ANY and ALL u ANY and ALL used with subqueries that produce single column of numbers u ALL –Condition only.
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.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
CS&E 1111 AcInnerJoins Inner Joins Objectives: Creating Queries with data from Multiple Tables Joining two tables using an Inner Join Referential Data.
IFS180 Intro. to Data Management Chapter 9 – Outer Joins.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Microsoft ® Office Access ® 2007 Training Datasheets II: Sum, sort, filter, and find your data ICT Staff Development presents:
Lecture 2 of Advanced Databases Advanced SQL Instructor: Mr.Ahmed Al Astal.
Chapter 9 Joining Data from Multiple Tables
Inner Join vs. Outer Join
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.
CSC271 Database Systems Lecture # 12. Summary: Previous Lecture  Row selection using WHERE clause  WHERE clause and search conditions  Sorting results.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 9 1 Microsoft Office Access 2003 Tutorial 9 – Using Action Queries, and Defining Table Relationships.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Oracle’s take on joins Where it differs from ANSI standard.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
IMS 4212: Intro to SQL 1 Dr. Lawrence West, Management Dept., University of Central Florida Introduction to SQL—Topics Introduction to.
Using Special Operators (LIKE and IN)
Week 10 Quiz 9 Answers Group 28 Christine Hallstrom Deena Phadnis.
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
One Customer has Many Pets; One Pet as One Customer, so Customer ID goes on Pet Table. One Pet has many Visits, but only one Visit refers.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making Chapter.
SQL 101 – Class 1 Lee Turner. Agenda 1. This is your life – SQL A brief history of SQL What SQL is and what it is not Normalization 2. Some Super Simple.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
WDM3304 week 6 Table Joins. Primary keys, foreign keys Primary key: A field of a table designated to provide a unique identifier for a specific row of.
Structured Query Language (SQL) Ask and ye shall receive. The Bible.
Database Programming Section 15 – Oracle Proprietary Join Syntax and Review 1.
1 Chapter 4: Creating Simple Queries 4.1 Introduction to the Query Task 4.2 Selecting Columns and Filtering Rows 4.3 Creating New Columns with an Expression.
Chapter 12 Subqueries and Merge Statements
Displaying Data from Multiple Tables (SQL99 Syntax with examples)
SQL Select Statement IST359.
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.
 Product Recommendations  Managing Product Recommendations  Types of Product Recommendations  Product Out of Stock  Out of Stock Management  Let.
INFANL01-3 ANALYSE 3 WEEK 3 March 2015 Institute voor Communication, Media en Informatietechnology.
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.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 5: SQL I Rob Gleasure robgleasure.com.
Day 5 - More Complexity With Queries Explanation of JOIN & Examples Explanation of JOIN & Examples Explanation & Examples of Aggregation Explanation &
Slide 1 of 32ASH-Training Querying and Managing Data Using SQL Server 2014 By: Segla In this session, you will learn to: Query data by using joins Query.
In-Class SQL Query Exercises For the Plumbing Supply Store Database.
Advanced SQL Advanced Database Dr. AlaaEddin Almabhouh.
IFS180 Intro. to Data Management Chapter 10 - Unions.
View Integration and Implementation Compromises
Database Management Systems II
Rob Gleasure robgleasure.com
Chapter 12 Subqueries and MERGE Oracle 10g: SQL
Inner Joins Objectives: Creating Queries with data from Multiple Tables Joining two tables using an Inner Join Referential Data Integrity Cascade Update.
Review of Main Database Features
Structured Query Language (SQL) William Klingelsmith
Chapter Name SQL: Data Manipulation
INNER JOIN INNER SPRIDEN SARADAP
Aggregations Various Aggregation Functions GROUP BY HAVING.
Rob Gleasure robgleasure.com
Chapter Name SQL: Data Manipulation Transparencies JOINS
Query Functions.
Rob Gleasure robgleasure.com
Subqueries.
Displaying Data from Multiple Tables
Presentation transcript:

Some relationship types Using the Builder2 schema

The staff table.

The customer table

The customer order (corder) table

Now let’s join them…

What sort of joins? One to many 2:many Many:Many Zero or one to many Reflexive

How do I write…? List all staff who took payment for orders and the orders for which they took payment. List all staff who were involved with orders and the orders they were involved with. List all staff and the customers they dealt with. List each staff member’s name, along with the name of his / her boss.

Creating Views The following are the fields in the stock table: Which of them do you think the customer needs to see? Is the Supplier_id enough information for the customer? Design a customer view.

Inner and Outer Joins An inner join occurs when records are selected from two tables and the values in one column from the first table are also found in a similar column in the second table.

Oracle Inner Joins The tables to be joined are listed in the FROM clause and then related together in the WHERE clause: SELECT staff_name, corderno FROM staff, corder WHERE staff_no = corder.staffpaid; Or SELECT supplier_name, stock_description FROM supplier, stock WHERE supplier.supplier_id = stock.supplier_id; Or SELECT supplier_name, stock_description FROM supplier sp, stock st WHERE sp.supplier_id = st.supplier_id;

Outcome…

ANSI Inner joins American National Standards Institute (ANSI) has a different join: A simple join can be specified with an ON or a USING statement. The columns to be joined on will be listed.

Using ON

Using USING

ANSI Natural join The columns to be joined are not specified, but rather are resolved by Oracle. They must be similarly named in the tables to be joined. However, this is not recommended, as sometimes the same name can mean different things in different contexts.

Outcome…

However…

Outer Joins An outer join can also return results from one table where the corresponding table did not have a matching value. For example, some suppliers are not supplying any stock. An outer join can show supplier details even if there is no corresponding stock. –See next slide.

ANSI outer join The ANSI outer join can be: –A left join (showing the full contents of the left table and any corresponding rows from the righthand table) –A right join (showing the full contents of the righthand table and any corresponding rows from the left table) –A full outer join (showing the full contents of the righthand and left hand tables, showing matches where appropriate).

Full outer join

Now let’s go back…

Exercises – task based queries Find out which suppliers have not delivered our orders. Find out the most profitable item we stock. –How are you making your judgement? Based on the last month’s sales, which stock item are we selling most of? –Write a query to display the quantity of the stock item, the quantity sold in the last month and the reorder level.