© 2007 by Prentice Hall6-1 Introduction to Oracle 10g Chapter 6 Creating Multitable Queries and Views James Perry and Gerald Post.

Slides:



Advertisements
Similar presentations
Advanced SQL (part 1) CS263 Lecture 7.
Advertisements

Multiple Table Queries
© Abdou Illia MIS Spring 2014
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Joins and Sub-queries in SQL.
Chapter 4 Joining Multiple Tables
A Guide to SQL, Seventh Edition. Objectives Use joins to retrieve data from more than one table Use the IN and EXISTS operators to query 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.
MULTIPLE-TABLE QUERIES
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
Multiple-Column Subqueries 12. Objectives After completing this lesson, you should be able to do the following: Write a multiple-column subquery Describe.
Instructor: Craig Duckett CASE, ORDER BY, GROUP BY, HAVING, Subqueries
Introduction to Oracle9i: SQL1 Subqueries. Introduction to Oracle9i: SQL2 Chapter Objectives Determine when it is appropriate to use a subquery Identify.
CSEN 5314 Quiz What type of join is needed when you wish to include rows that do not have matching values? A. Equi-joinB. Natural join C. Outer.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Database Systems More SQL Database Design -- More SQL1.
Structured Query Language Chapter Three DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Concepts of Database Management Sixth Edition
Microsoft Access 2010 Chapter 7 Using SQL.
Chapter 2 Basic SQL SELECT Statements
Introduction to Databases Chapter 7: Data Access and Manipulation.
Chapter 9 Joining Data from Multiple Tables
SQL advanced select using Oracle 1 7. Multiple Tables: Joins and Set Operations 8. Subqueries: Nested Queries.
ITBIS373 Database Development
Oracle Database Administration Lecture 2 SQL language.
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.
Fundamentals, Design, and Implementation, 9/e CPE 481 Database Processing Chapter 6 Structured Query Language (SQL) Instructor:Suthep Madarasmi, Ph.D.
Concepts of Database Management Seventh Edition
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
Nested Queries (Sub Queries) A nested query is a form of a SELECT command that appears inside another SQL statement. It is also termed as subquery. The.
1 Information Retrieval and Use (IRU) CE An Introduction To SQL Part 1.
11 Copyright © Oracle Corporation, All rights reserved. Creating Views.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Chapter 4 Multiple-Table Queries
Unit 4 Queries and Joins. Key Concepts Using the SELECT statement Statement clauses Subqueries Multiple table statements Using table pseudonyms Inner.
Join, Subqueries and set operators. Obtaining Data from Multiple Tables EMPLOYEES DEPARTMENTS … …
1 Multiple Table Queries. 2 Objectives  Retrieve data from more than one table by joining tables  Using IN and EXISTS to query multiple tables  Nested.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
SQL advanced select using Oracle 1. 2 Select Simple –data from a single table Advanced –data from more tables join sub-queries.
Chapter 12 Subqueries and Merge Statements
© 2007 by Prentice Hall4-1 Introduction to Oracle 10g Chapter 4 Modifying Data and Auditing Table Operations James Perry and Gerald Post.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
A Guide to SQL, Eighth Edition Chapter Five Multiple-Table Queries.
1 SQL – IV Grouping data from tables in SQL –The concept of grouping –GROUP BY clause –HAVING Clause –Determining whether values are unique –Group by using.
© 2007 by Prentice Hall2-1 Introduction to Oracle 10g Chapter 2 Overview of SQL and SQL*Plus James Perry and Gerald Post.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
1 Chapter 3 Single Table Queries. 2 Simple Queries Query - a question represented in a way that the DBMS can understand Basic format SELECT-FROM Optional.
 CONACT UC:  Magnific training   
 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.
CSC314 DAY 9 Intermediate SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall USING AND DEFINING VIEWS  Views provide users controlled.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
IFS180 Intro. to Data Management Chapter 10 - Unions.
Multiple-Column Subqueries
Chapter 12 Subqueries and MERGE Oracle 10g: SQL
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
Using the Set Operators
Contents Preface I Introduction Lesson Objectives I-2
IST 318 Database Administration
Using the Set Operators
Presentation transcript:

© 2007 by Prentice Hall6-1 Introduction to Oracle 10g Chapter 6 Creating Multitable Queries and Views James Perry and Gerald Post

© 2007 by Prentice Hall6-2 Chapter Outline Creating and Using Multitable Queries Creating and Using Views

© 2007 by Prentice Hall6-3 Table 6.1 Asking price distribution table CategoryIDLowLimitHighLimit 1000$0$50, $50,000$100, $100,000$150, $150,000$200, $200,000$250, $250,000$300, $300,000$350, $350,000$400, $400,000$2,000,000

© 2007 by Prentice Hall6-4 Table 6.2 SQL set operators Set operatorDescription UNIONReturns all unique rows retrieved by the queries. UNION ALLReturns all the rows retrieved by the queries, including any duplicate rows. INTERSECTReturns rows that are retrieved by both queries. MINUSReturns the rows that remain when the rows retrieved by a second query are removed (subtracted) from the rows retrieved by the first query.

© 2007 by Prentice Hall6-5 Table 6.3 ANY and ALL operator descriptions OperatorMeaning =ANYEqual to any value the subquery returns. It is the same as the IN operator. <ANYSmaller than the largest value the subquery returns. >ANYLarger than the smallest value the subquery returns. >ALLLarger than the largest value the subquery returns. <ALLSmaller than the smallest value the subquery returns.

© 2007 by Prentice Hall6-6 Table 6.4 Description of some of the user_views columns Column NameData TypeDescription view_nameVARCHAR2(30)Name of the view. text_lengthNUMBERNumber of characters in the view’s subquery. textLONGText of the view’s subquery that created the view.

© 2007 by Prentice Hall6-7 IDNameDiv 1001BobMkt 1002DawnSales 1003BettySales 1006NancyMkt 1009FredSales PK2Emp # Amount $2, $2, $1, $ $ $ $425 EmployeesSales Result of joining the Employees and Sales tables: from Employees from Sales 1002 Dawn Sales $2, Dawn Sales $2, Betty Sales $1, Betty Sales $ Fred Sales $ Fred Sales $ Fred Sales $ Joining two tables

© 2007 by Prentice Hall6-8 joining tables on primary key/foreign key pairs 6.2 Joining the Customers and Properties tables

© 2007 by Prentice Hall6-9 specifies column in both tables that links them 6.3 Joining tables on like-named columns

© 2007 by Prentice Hall Using a natural join

© 2007 by Prentice Hall Joining three tables and filtering rows

© 2007 by Prentice Hall6-12 IDNameDiv 1001BobMkt 1002DawnSales 1003BettySales 1006NancyMkt 1009FredSales PK2Emp # Amount $2, $2, $1, $200 SalespersonsSales Result of joining the Salespersons and Sales tables: from Salespersons from Sales 1002 Dawn Sales $2, Dawn Sales $2, Betty Sales $1, Betty Sales $ Bob Mkt null null null 1009 Nancy Mkt null null null 1009 Fred Sales null null null 6.6 Outer join illustration

© 2007 by Prentice Hall6-13 inner joinleft outer join SalespersonSales rows with matching values (selected rows) excluded rows rows with matching values excluded rows SalespersonSales selected rows 6.7 Venn diagrams showing inner join and left outer join

© 2007 by Prentice Hall Using a left outer join

© 2007 by Prentice Hall6-15 value 0 indicates no match in Listings (left) table 6.9 Showing non matching rows with a COUNT function

© 2007 by Prentice Hall Displaying the EmpSelfJoin table

© 2007 by Prentice Hall6-17 EmployeeIDBossID EmployeeIDBossID EmpSelfJoin eEmpSelfJoin m e.BossID = m.EmployeeID 6.11 Illustration of a table joined to itself by using aliases

© 2007 by Prentice Hall Listing managers and their employees with a self join query

© 2007 by Prentice Hall6-19 “Board of Directors” appears when the BossID is null 6.13 Managers and their employees produced using an outer join query

© 2007 by Prentice Hall6-20 non-equijoin join conditions 6.14 Creating the PriceCat table and running a non-equijoin query

© 2007 by Prentice Hall Comparing a non-equijoin and a right outer non-equijoin

© 2007 by Prentice Hall Using UNION in a compound query

© 2007 by Prentice Hall6-23 display homes newer by 18 years than the average for Arcata display agents who have the same title as Jessica Taylor 6.17 Using subqueries in WHERE clauses

© 2007 by Prentice Hall Examples of the IN operator and subqueries

© 2007 by Prentice Hall6-25 (additional rows are out of sight) 6.19 Description and contents of the AgentsHR table

© 2007 by Prentice Hall Using ALL and ANY operators in a query

© 2007 by Prentice Hall Using two subqueries and the ALL operator

© 2007 by Prentice Hall A correlated subquery to locate above-average asking prices

© 2007 by Prentice Hall A correlated subquery to display above-average salaries

© 2007 by Prentice Hall6-30 Count the customers without agents Count the customers without properties list the agents who are not designated “Licensed” 6.24 Using the EXISTS operator in several correlated subqueries

© 2007 by Prentice Hall Creating and describing views

© 2007 by Prentice Hall Displaying rows through the Nonbrokers view

© 2007 by Prentice Hall Defining a view with alternative column names

© 2007 by Prentice Hall Executing DML statements on a view

© 2007 by Prentice Hall Disallowing an update on a one-table complex view

© 2007 by Prentice Hall6-36 creating a multiple table view querying a multiple table view and the results 6.30 Creating a multiple table view and querying it

© 2007 by Prentice Hall6-37 creating a five-table view format columns display rows using the ForSale view 6.31 Creating a multiple table view joining five tables

© 2007 by Prentice Hall Displaying view information

© 2007 by Prentice Hall Listing and then dropping views you created