Notice that No where clause In the syntax.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Chapter 4 Joining Multiple Tables
Displaying Data from Multiple Tables
Group functions cannot be used in the WHERE clause: SELECT type_code FROM d_songs WHERE SUM (duration) = 100; (this will give an error)
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
1 Lecture 3: Subqueries DCO11310 Database Systems and Design By Rose Chang.
5 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
6 Copyright © 2004, Oracle. All rights reserved. Using Subqueries to Solve Queries.
6 Copyright © Oracle Corporation, All rights reserved. Subqueries.
4 Copyright © Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
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.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
 After completing this lesson, you should be able to do the following: ◦ Interpret the concept of a hierarchical query ◦ Create a tree-structured report.
Ceng 356-Lab1. Objectives After completing this lesson, you should be able to do the following: Get Familiar with the development environment List the.
Displaying Data from Multiple Tables. Obtaining Data from Multiple Tables Sometimes you need to use data from more than one table. In the example, the.
Objectives After completing this lesson, you should be able to do the following: Write SELECT statements to access data from more than one table using.
Objectives After completing this lesson, you should be able to do the following: Define subqueries Describe the types of problems that the subqueries.
4 Copyright © Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
4 Copyright © Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
4 Copyright © Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
Chapter 9 Joining Data from Multiple Tables
Sections 3 – Joins & Hierarchical Queries
Copyright © 2004, Oracle. All rights reserved. Lecture 6 Displaying Data from Multiple Tables ORACLE.
Oracle Database Administration Lecture 2 SQL language.
Basisdata Pertanian. After completing this lesson, you should be able to do the following:  Write SELECT statements to access data from more than one.
6 Copyright © 2004, Oracle. All rights reserved. Using Subqueries to Solve Queries.
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
Multiple Table Queries (Inner Joins) Week 3. Objective –Write SELECT statements to display data from more than one table using inner joins.
Join, Subqueries and set operators. Obtaining Data from Multiple Tables EMPLOYEES DEPARTMENTS … …
4 Copyright © Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
Copyright © 2004, Oracle. All rights reserved. D ISPLAYING D ATA FROM M ULTIPLE T ABLES.
5 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
5 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
Intermediate SQL: Aggregated Data, Joins and Set Operators.
Database Programming Sections 4 – Joins. Marge Hohly2 Overview  Oracle Proprietary Joins (8i and prior): Cartesian Product Equijoin Non-equijoin Outer.
Database Programming Section 15 – Oracle Proprietary Join Syntax and Review 1.
4 Copyright © Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
Displaying Data from Multiple Tables (SQL99 Syntax with examples)
Database Programming Sections 3 – Oracle Joins. Marge Hohly2 Obtaining Data from Multiple Tables: Using Joins.
6 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using Subqueries.
In this session, you will learn to: Query data by using joins Query data by using subqueries Objectives.
19 Copyright © Oracle Corporation, All rights reserved. Hierarchical Retrieval.
ORACLE SQL Fundamental II xpp-e-f 重點 xpp-e : Generating Reports by Grouping Related Data xpp-f : Hierarchical Retrieval.
Hierarchical Retrieval Fresher Learning Program December, 2011.
Special Joins Week 4. Objective –Write SELECT statements to display left, right and full outer joins.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
1 Ch. 11: Grouping Things Together  ANSI standard SQL Group functions: AVG, COUNT, MAX, MIN, STDDEV, SUM, VARIANCE  Others: 8i: GROUPING (used with CUBE.
7 Copyright © 2004, Oracle. All rights reserved. Hierarchical Retrieval.
1 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
4 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
Oracle 10g Retrieving Data Using the SQL SELECT Statement.
1 Copyright © 2009, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
4 Copyright © Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
6 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using Subqueries.
Displaying Data from Multiple Tables
Oracle Join Syntax.
Displaying Data from Multiple Tables
Displaying Data from Multiple Tables
Displaying Data from Multiple Tables
Displaying Data from Multiple Tables Using Joins
Oracle Join Syntax.
Writing Basic SQL SELECT Statements
Oracle Join Syntax.
分级取回数据 Schedule: Timing Topic 30 minutes Lecture 20 minutes Practice
DUAL TABLE The DUAL table has one row called "X" and one column called "DUMMY." The DUAL table is used to create SELECT statements and execute commands.
Displaying Data from Multiple Tables
Displaying Data from Multiple Tables
Displaying Data from Multiple Tables
Subqueries Schedule: Timing Topic 25 minutes Lecture
Presentation transcript:

Notice that No where clause In the syntax

Equijoins sometimes called Simple or inner join We can use column alias to recognize between columns have same name from two different tables.

Join conditions containing something other than equality operation (operator) never use = sign

Note: Can’t use the IN operator or be linked to another condition by the OR operator.

Note that department_name Contracting is retrieved although it has no department_id

Note that last_name Grant is retrieved although it has no department_id or departmant_name

Hierarchical queries are closely related to self- joins. You can use self-joins to see who is someone's direct manager. With hierarchical queries you can see not only the direct manager, but also who that manager works for, and so on. This lesson defines and gives examples of hierarchical queries. Using hierarchical queries, you can build an organization chart showing the structure of a company or a department. You can also use hierarchical queries to build a family tree with the eldest members of the family found close at the base or trunk of the tree and the youngest members representing branches of the tree. Branches can have their own branches, and so on.

HIERARCHICAL QUERIES hierarchical queries have their own new keywords: START WITH, CONNECT BY PRIOR, and LEVEL. START WITHSTART WITH is used to tell Oracle which row to use as its Root of the tree it is constructing CONNECT BY PRIORCONNECT BY PRIOR tells Oracle how to do the inter-row joins LEVEL LEVEL is how many steps down from the top of the tree we have taken.

LEVEL LEVEL is a pseudo-column used with hierarchical queries, and it counts the number of steps it has taken from the root of the tree.

If you wanted to create a report displaying company management levels, beginning with the highest level and indenting each of the following levels, then this would be easy to do using the LEVEL pseudo column and the LPAD function to indent employees based on their level.

So if you wanted to just not include a single row in your result you would use the WHERE clause to exclude that row, but in the result it would then look like Gietz worked directly for Kochhar, which he does not.

What is wrong in the following statement:What is wrong in the following statement: SELECT last_name, department_id, salary FROM employees START WITH last_name = 'King' CONNECT BY PRIOR manager_id = employee_id;

Note never use TABLE alias with USING clause

The column used in USING clause not necessary to be in select clause

Join using ON to specify the condition or the column used

Observe the employee_id column and the manager_id column

Number of rows returned in inner join was 19 rows In left outer join and right outer join was 20 rows While in full outer join is 21 rows

GOOD LUCK SEE YOU NEXT MEETING Raafat Rashad