Dr. Chen, Oracle Database System (Oracle) 1 Database Development DDL DML DCL JL_D.B. ORACLE (SQL Components) (Retrieve Data and Produce Information from.

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

© Abdou Illia MIS Spring 2014
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
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.
Dr. Chen, Oracle Database System (Oracle) 1 Chapter 12 Subqueries and Merge Statements (up to p.451) Jason C. H. Chen, Ph.D. Professor of MIS School of.
Chapter 11 Group Functions (up to p.402)
5 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
SUNY Morrisville-Norwich Campus-Week 10 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Introduction to Oracle9i: SQL1 Basic SQL SELECT Statements.
A Guide to Oracle9i1 Using SQL Queries to Insert, Update, Delete, and View Data Chapter 3.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Concepts of Database Management Sixth Edition
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.
Using SQL Queries to Insert, Update, Delete, and View Data © Abdou Illia MIS Spring 2015 Wednesday 1/28/2015 Chapter 3A.
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
SQL Joins.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Guide to Oracle10G1 Using SQL Queries to Insert, Update, Delete, and View Data Chapter 3.
Dr. Chen, Business Database Systems (Oracle) Chapter 2 Connecting to Oracle 11g and Basic SQL SELECT Statements Jason C.H. Chen, Ph.D. Professor of MIS.
Concepts of Database Management, Fifth Edition
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Dr. Chen, Oracle Database System (Oracle) 1 Chapter 4 Constraints Jason C. H. Chen, Ph.D. Professor of MIS School of Business Gonzaga University Spokane,
Concepts of Database Management, Fifth Edition Chapter 4: The Relational Model 3: Advanced Topics.
Chapter 5 Data Manipulation and Transaction Control
Chapter 9 Joining Data from Multiple Tables
ITBIS373 Database Development
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.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 9 1 Microsoft Office Access 2003 Tutorial 9 – Using Action Queries, and Defining Table Relationships.
SQL 101 for Web Developers 14 November What is a database and why have one? Tables, relationships, normalization SQL – What SQL is and isn’t – CRUD:
Dr. Chen, Oracle Database System (Oracle) 1 HW Discussion Chapter 5 (#9) –Why need two “deletes”? SQL> --9. SQL> SQL> DELETE FROM orderitems 2 WHERE order#
Dr. Chen, Oracle Database System (Oracle) 1 Chapter 6 Additional Database Objects (up to p.195 and all in the pptx file) Jason C. H. Chen, Ph.D. Professor.
Dr. Chen, Business Database Systems (Oracle) Instruction on Creating sql files and SPOOL Jason C.H. Chen, Ph.D. Professor of MIS School of Business, Gonzaga.
Dr. Chen, Business Database Systems JustLee DataBase Referential Integrity Jason C. H. Chen, Ph.D. Professor of MIS School of Business Administration Gonzaga.
Concepts of Database Management Seventh Edition
Oracle DML Dr. Bernard Chen Ph.D. University of Central Arkansas.
JOI/1 Data Manipulation - Joins Objectives –To learn how to join several tables together to produce output Contents –Extending a Select to retrieve data.
ADVANCED SQL SELECT QUERIES CS 260 Database Systems.
Chapter 4 Multiple-Table Queries
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
Join, Subqueries and set operators. Obtaining Data from Multiple Tables EMPLOYEES DEPARTMENTS … …
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making Chapter.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
(SQL - Structured Query Language)
A Guide to SQL, Eighth Edition Chapter Five Multiple-Table Queries.
Query Processing – Implementing Set Operations and Joins Chap. 19.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
 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.
LEC-8 SQL. Indexes The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
4 Copyright © Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
Dr. Chen, Oracle Database System (Oracle) 1 Basic Nested Queries and Views Jason C. H. Chen, Ph.D. Professor of MIS School of Business Gonzaga University.
Joining Tables Steve Perry
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
 2012 Pearson Education, Inc. All rights reserved.
Using the Set Operators
Basic Nested Queries and Views
INFO/CSE 100, Spring 2005 Fluency in Information Technology
David M. Kroenke and David J
Using the Set Operators
Contents Preface I Introduction Lesson Objectives I-2
Using the Set Operators
Manipulating Data Lesson 3.
Use of SQL – The Patricia database
Presentation transcript:

Dr. Chen, Oracle Database System (Oracle) 1 Database Development DDL DML DCL JL_D.B. ORACLE (SQL Components) (Retrieve Data and Produce Information from Multiple Tables)

Dr. Chen, Oracle Database System (Oracle) 2 Chapter 9 Joining Data from Multiple Tables (p ; p ) Jason C. H. Chen, Ph.D. Professor of MIS School of Business Gonzaga University Spokane, WA USA

Dr. Chen, Oracle Database System (Oracle) 3 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

Dr. Chen, Oracle Database System (Oracle) 4 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

Dr. Chen, Oracle Database System (Oracle) 5 Creating additional Tables for chapter 9 Run the following command for creating additional tables: SQL>start c:\oradata\chapter9\JLDB_Build_9.sql The following new four tables will be added to your database (see next slide for details): –Warehouses, –Publisher2, Publisher3 and –Employees

Dr. Chen, Oracle Database System (Oracle) 6 wh_idlocation NUMBER(2)VARCHAR2(12) IDNameContactPhone NUMBER(2)VARCHAR2(23)VARCHAR2(15)VARCHAR2(12) IDNameContactPhone NUMBER(2)VARCHAR2(23)VARCHAR2(15)VARCHAR2(12) EMPNOLNAMEFNAMEJOB HIREDATE DEPTNOMTHSALMGR NUMBER(4)VARCHAR2(20) VARCHAR2(15) VARCHAR2(19)DATENUMBER(2)NUMBER(7,2)NUMBER(4) pk warehouses Publishe2 Publishe3 Employees Publishe2 Publishe3 warehouses Additional Database for chapter 9 Do we really need to create two additional Publisher tables (i.e., Publisher2 and Publisher3) ?

Dr. Chen, Oracle Database System (Oracle) 7 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

Dr. Chen, Oracle Database System (Oracle) 8 How many records will be in the Cartesian Join? Figure 9-1Results of a Cartesian Product

Dr. Chen, Oracle Database System (Oracle) 9 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) They are useful when –performing certain statistical procedures for data analysis

Dr. Chen, Oracle Database System (Oracle) 10 Cartesian Join Example: Omitted Condition Figure 9-3 Producing an unintentional Cartesian join Q: Why unintentional Cartesian join is produced? A: Because Oracle didn’t know what data the two tables had in common. Q: How to solve the problem? A: Use of Equality Joins (or inner/simple/natu ral). -- chapter 9, Figure 9-3; p.288 SELECT title, name FROM books, publisher; (70 rows produced)

Dr. Chen, Oracle Database System (Oracle) 11 Cartesian Join Example: CROSS (Cartesian) JOIN Keywords Figure 9-4 Using the CROSS JOIN keywords -- chapter 9, Figure 9-2; p.287 SELECT isbn, title, location, ' ' Count FROM books, warehouses ORDER BY location, title; -- chapter 9, Figure 9-4; p.289 SELECT isbn, title, location, ' ' Count FROM books CROSS JOIN warehouses ORDER BY location, title; (42 rows produced) -- chapter 9, Figure 9-2b; p.287 SELECT count (location) FROM books, warehouses ORDER BY location, title;

Dr. Chen, Oracle Database System (Oracle) 12 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

Dr. Chen, Oracle Database System (Oracle) 13 Joining Multiple Tables Join: combine data from multiple database tables using foreign key references SELECT field1, field2,... FROM table1, table2 WHERE table1.joinfield = table2.joinfield AND search_condition(s); If tables share field names, must prefix field in select with table name (table1.field1, table2.field1) Join condition: part of where clause indicating how tables are related (table1.foreign_key = table2.primary key) Search conditions can be added to join condition using AND operator

Dr. Chen, Oracle Database System (Oracle) 14 Inner Join (cont.) -- Exatra example SELECT s_id, s_last, s_first, student.f_id, f_last FROM student, faculty WHERE student.f_id = faculty.f_id; S_ID S_LAST S_FIRST F_ID F_LAST Jones Tammy 1 Cox 2Perez Jorge 1 Cox 3Marsh John 1 Cox 4Smith Mike 2 Blanchard 5Johnson Lisa 4 Sheng 6Nguyen Ni 3 Williams 6 rows selected. Q: why “Brown” is not on the result? Q: How many rows will be produced if “C-Join” is used?

Dr. Chen, Oracle Database System (Oracle) 15 Natural Join – Inner Join It can be used when the tables have a single commonly named and defined column. -- Extra Example SELECT s_id, s_last, s_first, student.f_id, f_last FROM student, faculty WHERE student.f_id = faculty.f_id; -- Use NATURAL JOIN SELECT s_id, s_last, s_first, f_id, f_last FROM student NATURAL JOIN faculty; S_ID S_LAST S_FIRST F_ID F_LAST Jones Tammy 1 Cox 2Perez Jorge 1 Cox 3Marsh John 1 Cox 4Smith Mike 2 Blanchard 5Johnson Lisa 4 Sheng 6Nguyen Ni 3 Williams 6 rows selected.

Dr. Chen, Oracle Database System (Oracle) 16 Equality Joins (Traditional Method): WHERE Clause Example Figure 9-6 An equality join

Dr. Chen, Oracle Database System (Oracle) 17 Qualifying Column Names Columns in both tables must be qualified Figure 9-7 A “column ambiguously defined” error Which table is “pubid” from? Is it from publisher or books? -- chapter 9, Figure 9-7(b); p.292 SELECT title, books.pubid, name FROM books, publisher WHERE books.pubid = publisher.pubid;

Dr. Chen, Oracle Database System (Oracle) 18 WHERE Clause Supports Join and Other Conditions Figure 9-8 Including search and join conditions in a WHERE clause -- Use aliases -- chapter 9, Figure 9-9; p.294 SELECT b.title, b.pubid, p.name FROM books b, publisher p WHERE b.pubid = p.pubid AND (b.cost < 15 OR p.pubid = 1) ORDER BY title;

Dr. Chen, Oracle Database System (Oracle) 19 Using a Query Design Diagram Helpful for creating complicated queries Can use a formula to derive actual query from diagram Customers customer# (j) lastname (d) firstname (d) Orders order# (j) customer# (j) Orderitems order# (j) isbn (j) Query: Display customers’ lastname, firstname and books’ title they purchased Books isbn (j) title (d) j: join s: search d: display

Dr. Chen, Oracle Database System (Oracle) 20 Query: Display customers’ lastname, firstname and books’ title they purchased j: join s: search d: display Customers customer# (j) lastname (d) firstname (d) Orders order# (j) customer# (j) Orderitems order# (j) isbn (j) Books isbn (j) title (d) You can derive your query from the diagram by following these steps: 1. Place the display fields in the SELECT clause 2. List all of the tables in the FROM clause 3. Include the links in join conditions in the WHERE clause 4. Include all of the search fields in the WHERE clause (if needed) Figure: Join query design diagram

Dr. Chen, Oracle Database System (Oracle) 21 Query: Display customers’ lastname, firstname and books’ title they purchased j: join s: search d: display Customers customer# (j) lastname (d) firstname (d) Orders order# (j) customer# (j) Orderitems order# (j) isbn (j) Books isbn (j) title (d) Figure: Join query design diagram -- chapter 9, Figure 9-10; p.295 SELECT c.lastname, c.firstname, b.title FROM customers c, orders o, orderitems oi, books b WHERE c.customer# = o.customer# AND o.order# = oi.order# AND oi.isbn = b.isbn ORDER BY lastname, firstname;

Dr. Chen, Oracle Database System (Oracle) 22 Joining More Than Two Tables Figure 9-10 Joining four tables Joining four tables requires three join conditions Joining N tables requires ___ join conditions

Dr. Chen, Oracle Database System (Oracle) 23 Query: Display customers’ lastname, firstname and books’ title and only in ‘COMPUTER’ category j: join s: search d: display Customers customer# (j) lastname (d) firstname (d) Orders order# (j) customer# (j) Orderitems order# (j) isbn (j) Books isbn (j) title (d) _______ Figure: Join query design diagram -- chapter 9, Figure 9-10; p.295 SELECT c.lastname, c.firstname, b.title FROM customers c, orders o, orderitems oi, books b WHERE c.customer# = o.customer# AND o.order# = oi.order# AND oi.isbn = b.isbn ORDER BY lastname, firstname; AND category = ‘COMPUTER’ category (s)

Dr. Chen, Oracle Database System (Oracle) 24 Equality Joins: NATURAL JOIN Figure 9-12 Using the NATURAL JOIN keywords

Dr. Chen, Oracle Database System (Oracle) 25 No Qualifiers with a NATURAL JOIN Figure 9-13 Column qualifier error with a NATURAL JOIN Natural Join keyword (e.g, pubid), we are not required to be specified when the two tables have it in common. Therefore most developers avoid using a NATURAL JOIN because it can cause unexpected results.

Dr. Chen, Oracle Database System (Oracle) 26 Equality Joins: JOIN…USING Figure 9-14 Performing a join with the JOIN … USING keywords

Dr. Chen, Oracle Database System (Oracle) 27 Break Assignments (#2 & #5 on p. 329; see at the end of the slides) Figure out how to produce the output with ‘$’ displayed (below is a sample output for #5, p.329) – hint: a) column … b) TO_CHAR (see p and ‘learning to learn’) TITLE PROFIT PAINLESS CHILD-REARING $37.45 HOW TO MANAGE THE MANAGER $16.55 PAINLESS CHILD-REARING $37.45 TO_CHAR( )PROFIT,_______

Dr. Chen, Oracle Database System (Oracle) 28 Query: list all author IDs with books in the ‘Children’ category Query: list all author IDs with books in the ‘Family Life’ category SELECT ba.authorid FROM books b JOIN bookauthor ba USING (isbn) WHERE category = 'FAMILY LIFE‘; SELECT ba.authorid FROM books b JOIN bookauthor ba USING (isbn) WHERE category = 'CHILDREN';

Dr. Chen, Oracle Database System (Oracle) 29 Query: list all author IDs with books in the ‘Family Life’ or ‘Children’ category -- chapter 9, Figure 9-28; p. 313(version 1) SELECT ba.authorid FROM books b JOIN bookauthor ba USING (isbn) WHERE category = ‘FAMILY LIFE’ Anything not appropriate in the output? OR category = ‘CHILDREN’; How to take care this type of problem in an easy way? -- chapter 9, Figure 9-28; p. 313(version 2) SELECT _______ (ba.authorid) FROM books b JOIN bookauthor ba USING (isbn) WHERE category = 'FAMILY LIFE' OR category = 'CHILDREN'; What else we can achieve the same goal (and other more complicated situation) ?

Dr. Chen, Oracle Database System (Oracle) 30 Using Set Operators to Combine Query Results Performs set operations on outputs of two unrelated queries They all require that both queries –have the same number of display fields in the SELECT statement, and that –each field in the first query has the same data type as the corresponding column in the second query.

Dr. Chen, Oracle Database System (Oracle) 31 AB SET THEORY

Dr. Chen, Oracle Database System (Oracle) 32 C SET THEORY =A-B =B-A =A INTERSECT B= All Regions =A UNION B (with C counted just once) A-B B-A A B C

Dr. Chen, Oracle Database System (Oracle) 33 C SET THEORY A MINUS B=D B MINUS A=E A INTERSECT B= A UNION B = D E A UNION ALL B = D+C+E+__ C C D+C+E A B

Dr. Chen, Oracle Database System (Oracle) 34 Oracle 11g/SQL Set Operator (Table 9-2) UNION (see Figure 9-28) –returns all rows from both queries, but ONLY displays duplicate rows once UNION ALL (see Figure 9-30) –returns all (duplicate) rows from both queries, and displays ALL duplicate rows INTERSECT (see Figure 9-34) –returns all matching rows that are returned by both queries MINUS (see Figure 9-35) –returns all rows returned by the first query minus the matching rows returned by the second query  Use to select data from multiple tables not connected with foreign key relationships  Used to combine the results of two or more SELECT statements

Dr. Chen, Oracle Database System (Oracle) 35 Query: list all author IDs with books in the ‘Family Life’ or ‘Children’ category SELECT ba.authorid FROM books b JOIN bookauthor ba USING (isbn) WHERE category = 'FAMILY LIFE‘ SELECT ba.authorid FROM books b JOIN bookauthor ba USING (isbn) WHERE category = 'CHILDREN'; UNION Figure 9-28 Producing an unduplicated combined list with the UNION set operator

Dr. Chen, Oracle Database System (Oracle) 36 Set Operators: UNION and UNION ALL Examples What is the “difference” on the outputs?

Dr. Chen, Oracle Database System (Oracle) 37 Figure 9-34 Identifying overlapping values with the INTERSECT set operator Query: list all customer numbers and those customers who have placed an order recently SELECT customer# FROM customers SELECT customer# FROM orders; INTERSECT

Dr. Chen, Oracle Database System (Oracle) 38 Query: list all customer numbers but haven’t placed an order recently Figure 9-35 Subtract result sets with the MINUS set operator SELECT customer# FROM customers SELECT customer# FROM orders; MINUS

Dr. Chen, Oracle Database System (Oracle) 39 Query: A list of faculty members whose offices are in the BUS building. (Extra example) FACULTY  f_first (d)  f_last (d)  loc_id (j) LOCATION  loc_id (j)  bldg_code (s) SELECT f_first, f_last FROM faculty, location WHERE faculty.loc_id = location.loc_id AND bldg_code = 'BUS'; MORE EXAMPLES on SET OPERATORS You need to run the following command to make the example c:\oradata\NW_CW\northwoods.sql

Dr. Chen, Oracle Database System (Oracle) 40 Query: A list of faculty members who have taught a course in the BUS building. FACULTY  f_first (d)  f_last (d)  f_id (j) LOCATION  loc_id (j)  bldg_code (s) COURSE_ SECTION  f_id (j)  loc_id (j) SELECT DISTINCT f_first, f_last FROM faculty, location, course_section WHERE faculty.f_id = course_section.f_id AND location.loc_id = course_section.loc_id AND bldg_code = 'BUS';

Dr. Chen, Oracle Database System (Oracle) 41 Query: A list of faculty members whose offices are in the BUS building or who have taught a course in the BUS building. (extra example) SELECT f_first, f_last FROM faculty, location WHERE faculty.loc_id = location.loc_id AND bldg_code = 'BUS' SELECT f_first, f_last FROM faculty, location, course_section WHERE faculty.f_id = course_section.f_id AND location.loc_id = course_section.loc_id AND bldg_code = 'BUS'; UNION Office in ‘BUS’ Taught courses in ‘BUS’

Dr. Chen, Oracle Database System (Oracle) 42 Query: A list of faculty members whose offices are in the BUS building and who have taught a course in the BUS building. (extra example) SELECT f_first, f_last FROM faculty, location WHERE faculty.loc_id = location.loc_id AND bldg_code = 'BUS' SELECT f_first, f_last FROM faculty, location, course_section WHERE faculty.f_id = course_section.f_id AND location.loc_id = course_section.loc_id AND bldg_code = 'BUS'; INTERSECT Office in ‘BUS’ Taught courses in ‘BUS’

Dr. Chen, Oracle Database System (Oracle) 43 And NEXT... Query: A list of faculty members who have taught a course in the BUS building, but whose office are NOT located in the BUS SELECT f_first, f_last FROM faculty, location, course_section WHERE faculty.f_id = course_section.f_id AND location.loc_id = course_section.loc_id AND bldg_code = 'BUS'; SELECT f_first, f_last FROM faculty, location WHERE faculty.loc_id = location.loc_id AND bldg_code = 'BUS' MINUS Office in ‘BUS’ Taught courses in ‘BUS’

Dr. Chen, Oracle Database System (Oracle) 44 Practice all the examples in the text. A Script file is available on the Bb (file name: ch9Queries.sql) After completing all examples, do the HW.

Dr. Chen, Oracle Database System (Oracle) 45 Homework - Hands-On Assignments Read and Practice all examples on Chapters 9 1. Run the script files (in the folder \oradata\chapter9\): JLDB_Build_9.sql 2a. Read Oracle assignment and create a script file Oracle_ch9_Lname_Fname.sql for questions (#2 & #5 ; p.329) on “Hands-on Assignments” (use TWO SQL queries, traditional one and with “JOIN” read instructions carefully) 2b. Be sure to use i) traditional method, ii) JOIN keyword, iii) draw Query Design Diagrams for each problem, and iv) use COLUMN statement to produce readable outputs – see next slide for details 3. Execute and test one problem at a time and make sure they are all running successfully. 4. When you done, spool the script files (see next slide for spooling instructions) and the file 5. Include Query Design Diagrams me with one attachment (Oracle_ch9_Spool_Lname_Fname.) to: with subject title of Bmis441-01_Oracle_ch9 (or Bmis441-02_Oracle_ch9)

Dr. Chen, Oracle Database System (Oracle) 46 Bonus Assignment --**************************************************************** -- Marketing department is analyzing books that don't sell. -- A list of ISBNs and Book Titles for all books is needed. -- Use a set operation (based on JL_Database to complete this task. --**************************************************************** -- a sample solution ISBN TITLE HOW TO GET FASTER PIZZA THE WOK WAY TO COOK BUILDING A CAR WITH TOOTHPICKS

Dr. Chen, Oracle Database System (Oracle) 47 How to Spool your Script and Output Files and add Query Design Diagrams After you tested the script file of Oracle_ch9_Lname_Fname.sql successfully, follow the instructions below to spool both script and output files: Step 0. Run the following script file from SQL*Plus (since you have created JLDB tables) –Start c:\oradata\chapter9\JLDB_Build_9.sql 1. type the following on SQL> –Spool c:\oradata\Oracle_ch9_Spool_Lname_Fname.txt (make sure your name is entered) 2. open Oracle_ch9_Lname_Fname.sql that you already tested 3. copy and paste all the SQL commands (including all comments) to the SQL*PLUS 4. type Spool Off on the SQL> The output should contain your personal information, all SQL commands and their solution on the.txt file and saved in C: drive (oradata\folder). Be sure that COLUMN commands might be needed on the script file to align the output.

Dr. Chen, Oracle Database System (Oracle) 48 How to Spool your Script and Output Files and add Query Design Diagrams (continued) 5. Next, you should use MS/Word to open the *.txt file and include/DRAW “Query Design Diagram” figures for queries with multiple tables. You may use font of “Courier new” to align the output. 6. Save it as *.docx file. me with the *.doc (or *.docx) file that includes all required documents with attachment to: with subject title of Bmis441-01_Oracle_ch9 (or Bmis441-02_Oracle_ch9)

Dr. Chen, Oracle Database System (Oracle) 49 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

Dr. Chen, Oracle Database System (Oracle) 50 Summary (continued) Inner joins are categorized as being equality, non- equality, 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