Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL



Similar documents
Lab # 5. Retreiving Data from Multiple Tables. Eng. Alaa O Shama

Oracle SQL. Course Summary. Duration. Objectives

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Using SQL Queries to Insert, Update, Delete, and View Data: Joining Multiple Tables. Lesson C Objectives. Joining Multiple Tables

Oracle Database 10g: Introduction to SQL

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved.

Oracle Database 12c: Introduction to SQL Ed 1.1

Displaying Data from Multiple Tables

GET DATA FROM MULTIPLE TABLES QUESTIONS

Oracle Database: SQL and PL/SQL Fundamentals

Lecture Slides 4. SQL Summary. presented by Timothy Heron. Indexes. Creating an index. Mathematical functions, for single values and groups of values.

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved.

Oracle Database: SQL and PL/SQL Fundamentals NEW

Unit 3. Retrieving Data from Multiple Tables

Performing Queries Using PROC SQL (1)

Oracle 10g PL/SQL Training

Introducing Microsoft SQL Server 2012 Getting Started with SQL Server Management Studio

Database CIS 340. lab#6. I.Arwa Najdi

Querying Microsoft SQL Server

Oracle Database: SQL and PL/SQL Fundamentals

MOC 20461C: Querying Microsoft SQL Server. Course Overview

SQL. by Steven Holzner, Ph.D. ALPHA. A member of Penguin Group (USA) Inc.

Querying Microsoft SQL Server 2012

Define terms Write single and multiple table SQL queries Write noncorrelated and correlated subqueries Define and use three types of joins

Displaying Data from Multiple Tables. Copyright 2006, Oracle. All rights reserved.

Course 10774A: Querying Microsoft SQL Server 2012

Course ID#: W 35 Hrs. Course Content

Course 10774A: Querying Microsoft SQL Server 2012 Length: 5 Days Published: May 25, 2012 Language(s): English Audience(s): IT Professionals

Where? Originating Table Employees Departments

Querying Microsoft SQL Server 20461C; 5 days

Effective Use of SQL in SAS Programming

1 Structured Query Language: Again. 2 Joining Tables

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

Useful Business Analytics SQL operators and more Ajaykumar Gupte IBM

Querying Microsoft SQL Server Course M Day(s) 30:00 Hours

MOC QUERYING MICROSOFT SQL SERVER

Course 20461C: Querying Microsoft SQL Server Duration: 35 hours

Introduction to Querying & Reporting with SQL Server

RDBMS Using Oracle. Lecture Week 7 Introduction to Oracle 9i SQL Last Lecture. kamran.munir@gmail.com. Joining Tables

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

Programming with SQL

Oracle Database 11g SQL

Join Example. Join Example Cart Prod Comprehensive Consulting Solutions, Inc.All rights reserved.

Querying Microsoft SQL Server 2012

Outline. SAS-seminar Proc SQL, the pass-through facility. What is SQL? What is a database? What is Proc SQL? What is SQL and what is a database

WRITING EFFICIENT SQL. By Selene Bainum

Querying Microsoft SQL Server 2012

Oracle Database 11g: SQL Tuning Workshop Release 2

Advanced SQL - Subqueries and Complex Joins

ICAB4136B Use structured query language to create database structures and manipulate data

A basic create statement for a simple student table would look like the following.

Information Systems SQL. Nikolaj Popov

Displaying Data from Multiple Tables. Chapter 4

SQL SELECT Query: Intermediate

Relational Division and SQL

MySQL for Beginners Ed 3

Business Systems Analysis Certificate Program. Millennium Communications & Training Inc. 2013, All rights reserved


Querying Microsoft SQL Server (20461) H8N61S

CHAPTER 12. SQL Joins. Exam Objectives

Querying Microsoft SQL Server Querying Microsoft SQL Server D. Course 10774A: Course Det ails. Co urse Outline

SQL Server. 1. What is RDBMS?

In this Lecture SQL SELECT. Example Tables. SQL SELECT Overview. WHERE Clauses. DISTINCT and ALL SQL SELECT. For more information

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

Oracle Database: SQL and PL/SQL Fundamentals NEW

Talking to Databases: SQL for Designers

SQL Programming. Student Workbook

Course -Oracle 10g SQL (Exam Code IZ0-047) Session number Module Topics 1 Retrieving Data Using the SQL SELECT Statement

Information Systems (Informationssysteme)

Oracle Database 11g: SQL Tuning Workshop

Displaying Data from Multiple Tables

SAP BO Course Details

A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX

Relational Database: Additional Operations on Relations; SQL

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

CS 338 Join, Aggregate and Group SQL Queries

AV-005: Administering and Implementing a Data Warehouse with SQL Server 2014

Inquiry Formulas. student guide

Demystifying PROC SQL Join Algorithms Kirk Paul Lafler, Software Intelligence Corporation

Introduction to Microsoft Jet SQL

Beginning C# 5.0. Databases. Vidya Vrat Agarwal. Second Edition

Scenario 2: Cognos SQL and Native SQL.

SQL JOINs and VIEWs. Chapter 3.3 V3.0. Napier University Dr Gordon Russell

Structured Query Language (SQL)

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)

Instant SQL Programming

SQL. Short introduction

SQL SUBQUERIES: Usage in Clinical Programming. Pavan Vemuri, PPD, Morrisville, NC

Introduction to SQL and SQL in R. LISA Short Courses Xinran Hu

Alternatives to Merging SAS Data Sets But Be Careful

White Paper. Blindfolded SQL Injection

The Relational Algebra

DATABASE DESIGN AND IMPLEMENTATION II SAULT COLLEGE OF APPLIED ARTS AND TECHNOLOGY SAULT STE. MARIE, ONTARIO. Sault College

SQL Basics. Introduction to Standard Query Language

Foundations & Fundamentals. A PROC SQL Primer. Matt Taylor, Carolina Analytical Consulting, LLC, Charlotte, NC

SECTION 3 LESSON 1. Destinations: What s in My Future?

Database Query 1: SQL Basics

Transcription:

Chapter 9 Joining Data from Multiple Tables Oracle 10g: SQL

Objectives Identify a Cartesian join Create an equality join using the WHERE clause Create an equality join using the JOIN keyword Create a non-equality join using the WHERE clause Create a non-equality join using the JOIN ON approach Oracle 10g: SQL 2

Objectives (continued) Create a self-join using the WHERE clause Create a self-join using the JOIN keyword Distinguish an inner join from an outer join Create an outer join using the WHERE clause Create an outer join using the OUTER keyword Use set operators to combine the results of multiple queries Oracle 10g: SQL 3

Purpose of Joins Joins are used to link tables and reconstruct data in a relational database Joins can be created through: Conditions in a WHERE clause Use of JOIN keywords in FROM clause Oracle 10g: SQL 4

Cartesian Joins Created by omitting joining condition in the WHERE clause or through CROSS JOIN keywords in the FROM clause Results in every possible row combination (m * n) Oracle 10g: SQL 5

Cartesian Join Example: Omitted Condition Oracle 10g: SQL 6

Cartesian Join Example: CROSS JOIN Keywords Oracle 10g: SQL 7

Equality Joins Link rows through equivalent data that exists in both tables Created by: Creating equivalency condition in the WHERE clause Using NATURAL JOIN, JOIN USING, or JOIN ON keywords in the FROM clause Oracle 10g: SQL 8

Equality Joins: WHERE Clause Example Oracle 10g: SQL 9

Qualifying Column Names Columns in both tables must be qualified Oracle 10g: SQL 10

WHERE Clause Supports Join and Other Conditions Oracle 10g: SQL 11

Joining More Than Two Tables Joining 4 tables requires 3 join conditions Oracle 10g: SQL 12

Equality Joins: NATURAL JOIN Oracle 10g: SQL 13

No Qualifiers with a NATURAL JOIN Oracle 10g: SQL 14

Equality Joins: JOIN USING Oracle 10g: SQL 15

Equality Joins: JOIN ON Required if column names are different Oracle 10g: SQL 16

JOIN Keyword Overview Use JOIN USING when tables have one or more columns in common Use JOIN ON when same named columns are not involved or a condition is needed to specify a relationship other than equivalency (next section) Using the JOIN keyword frees the WHERE clause for exclusive use in restricting rows Oracle 10g: SQL 17

Non-Equality Joins In WHERE clause, use any comparison operator other than the equal sign In FROM clause, use JOIN ON keywords with a non-equivalent condition Oracle 10g: SQL 18

Non-Equality Joins: WHERE Clause Example Oracle 10g: SQL 19

Non-Equality Joins: JOIN ON Example Oracle 10g: SQL 20

Self-Joins Used to link a table to itself Requires the use of table aliases Requires the use of a column qualifier Oracle 10g: SQL 21

Customer Table Example Oracle 10g: SQL 22

Self-Joins: WHERE Clause Example Oracle 10g: SQL 23

Self-Joins: JOIN ON Example Oracle 10g: SQL 24

Outer Joins Use outer joins to include rows that do not have a match in the other table In WHERE clause, include outer join operator (+) immediately after the column name of the table with missing rows to add NULL rows In FROM clause, use FULL, LEFT, or RIGHT with OUTER JOIN keywords Oracle 10g: SQL 25

Outer Joins: WHERE Clause Example Oracle 10g: SQL 26

Outer Joins: OUTER JOIN Keyword Example Oracle 10g: SQL 27

Outer Joins (continued) If multiple join conditions are used, the outer join condition may be required in all the join conditions to retain non-matching rows Oracle 10g: SQL 28

Set Operators Used to combine the results of two or more SELECT statements Oracle 10g: SQL 29

Set Operators: UNION Example Oracle 10g: SQL 30

Set Operators: INTERSECT Example Oracle 10g: SQL 31

Set Operators: MINUS Example Oracle 10g: SQL 32

Summary Data stored in multiple tables regarding a single entity can be linked together through the use of joins A Cartesian join between two tables returns every possible combination of rows from the tables; the resulting number of rows is always m * n An equality join is created when the data joining the records from two different tables are an exact match A non-equality join establishes a relationship based upon anything other than an equal condition Self-joins are used when a table must be joined to itself to retrieve needed data Oracle 10g: SQL 33

Summary (continued) Inner joins are categorized as being equality, nonequality, or self-joins An outer join is created when records need to be included in the results without having corresponding records in the join tables The record is matched with a NULL record so it will be included in the output Set operators such as UNION, UNION ALL, INTERSECT, and MINUS can be used to combine the results of multiple queries Oracle 10g: SQL 34