0% found this document useful (0 votes)
139 views2 pages

DP 6 4 Practice

Uploaded by

Michał
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views2 pages

DP 6 4 Practice

Uploaded by

Michał
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Database Programming with SQL

6-4: Self Joins and Hierarchical Queries


Practice Activities
Objectives
• Construct and execute a SELECT statement to join a table to itself using a self-join
• Interpret the concept of a hierarchical query
• Create a tree-structured report
• Format hierarchical data
• Exclude branches from the tree structure

Vocabulary
Identify the vocabulary word for each definition below.

Joins a table to itself

Retrieves data based on a natural hierarchical relationship


between rows in a table
Determines the number of steps down from the beginning row
that should be returned by a hierarchical query
Identifies the beginning row for a hierarchical query

Specifies the relationship between parent rows and child rows of


a hierarchical query

Try It / Solve It

For each problem, use the Oracle database.

1. Display the employee’s last name and employee number along with the manager’s last name and
manager number. Label the columns: Employee, Emp#, Manager, and Mgr#, respectively.

2. Modify question 1 to display all employees and their managers, even if the employee does not
have a manager. Order the list alphabetically by the last name of the employee.

3. Display the names and hire dates for all employees who were hired before their managers, along
with their managers’ names and hire dates. Label the columns Employee, Emp Hired, Manager
and Mgr Hired, respectively.

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
4. Write a report that shows the hierarchy for Lex De Haans department. Include last name, salary,
and department id in the report.

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

6. Create a report that shows the organization chart for the entire employee table. Write the report
so that each level will indent each employee 2 spaces. Since Oracle Application Express cannot
display the spaces in front of the column, use - (minus) instead.

7. Re-write the report from 6 to exclude De Haan and all the people working for him.

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy