Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "© 2007 by Prentice Hall6-1 Introduction to Oracle 10g Chapter 6 Creating Multitable Queries and Views James Perry and Gerald Post."— Presentation transcript:

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

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

3 © 2007 by Prentice Hall6-3 Table 6.1 Asking price distribution table CategoryIDLowLimitHighLimit 1000$0$50,000 1010$50,000$100,000 1020$100,000$150,000 1030$150,000$200,000 1040$200,000$250,000 1050$250,000$300,000 1060$300,000$350,000 1070$350,000$400,000 1080$400,000$2,000,000

4 © 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.

5 © 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.

6 © 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.

7 © 2007 by Prentice Hall6-7 IDNameDiv 1001BobMkt 1002DawnSales 1003BettySales 1006NancyMkt 1009FredSales PK2Emp # Amount 211002$2,000 221002$2,200 231003$1,800 241003$200 251009$600 261009$750 271009$425 EmployeesSales Result of joining the Employees and Sales tables: from Employees from Sales 1002 Dawn Sales 21 1002 $2,000 1002 Dawn Sales 22 1002 $2,200 1003 Betty Sales 23 1003 $1,800 1003 Betty Sales 24 1003 $200 1009 Fred Sales 25 1009 $600 1009 Fred Sales 26 1009 $750 1009 Fred Sales 27 1009 $425 6.1 Joining two tables

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

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

10 © 2007 by Prentice Hall6-10 6.4 Using a natural join

11 © 2007 by Prentice Hall6-11 6.5 Joining three tables and filtering rows

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

13 © 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

14 © 2007 by Prentice Hall6-14 6.8 Using a left outer join

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

16 © 2007 by Prentice Hall6-16 6.10 Displaying the EmpSelfJoin table

17 © 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

18 © 2007 by Prentice Hall6-18 6.12 Listing managers and their employees with a self join query

19 © 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

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

21 © 2007 by Prentice Hall6-21 6.15 Comparing a non-equijoin and a right outer non-equijoin

22 © 2007 by Prentice Hall6-22 6.16 Using UNION in a compound query

23 © 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

24 © 2007 by Prentice Hall6-24 6.18 Examples of the IN operator and subqueries

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

26 © 2007 by Prentice Hall6-26 6.20 Using ALL and ANY operators in a query

27 © 2007 by Prentice Hall6-27 6.21 Using two subqueries and the ALL operator

28 © 2007 by Prentice Hall6-28 6.22 A correlated subquery to locate above-average asking prices

29 © 2007 by Prentice Hall6-29 6.23 A correlated subquery to display above-average salaries

30 © 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

31 © 2007 by Prentice Hall6-31 6.25 Creating and describing views

32 © 2007 by Prentice Hall6-32 6.26 Displaying rows through the Nonbrokers view

33 © 2007 by Prentice Hall6-33 6.27 Defining a view with alternative column names

34 © 2007 by Prentice Hall6-34 6.28 Executing DML statements on a view

35 © 2007 by Prentice Hall6-35 6.29 Disallowing an update on a one-table complex view

36 © 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

37 © 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

38 © 2007 by Prentice Hall6-38 6.32 Displaying view information

39 © 2007 by Prentice Hall6-39 6.33 Listing and then dropping views you created


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

Similar presentations


Ads by Google