Q
Problem solve Get help with specific problems with your technologies, process and projects.

# Showing inheritance

We are trying to show inheritance. We have a table with a parent-child relationship:

```SELECT  *
FROM    glen_test;

TYPE    PARENT PROPERTY
------- ------ --------
A       null          1
A       null          2
B       A             3
B       A             4
C       B             5
D       B             6
```
The table is interpreted like this:
• Type A has properties 1 and 2.
• Type B has properties 1, 2, 3 and 4: it inherits properties 1 and 2 from its parent (A), and has properties 3 and 4 directly.
• Type C has all the properties of all its ancestors (1 and 2 from A, 3 and 4 from B) as well as its own property (5).
• Type D is like C
We want to show all the properties that each type has and the ancestor (if any) from which they were inherited, like this
```
TYPE   ANCESTOR PROPERTY
------ -------- --------
A      null            1
A      null            2
B      A               1
B      A               2
B      null            3
B      null            4
C      A               1
C      A               2
C      B               3
C      B               4
C      null            5
D      A               1
D      A               2
D      B               3
D      B               4
D      null            6
```
We've tried using CONNECT BY ... PRIOR but with no success. Here is the code used to create the table:
```CREATE TABLE  glen_test
(
type      VARCHAR2 (10),
parent    VARCHAR2 (10),
PROPERTY  NUMBER
);

INSERT INTO glen_test ( type, parent, property )
VALUES ( 'A', NULL, 1);
INSERT INTO glen_test ( type, parent, property )
VALUES ( 'A', NULL, 2);
INSERT INTO glen_test ( type, parent, property )
VALUES ( 'B', 'A', 3);
INSERT INTO glen_test ( type, parent, property )
VALUES ( 'B', 'A', 4);
INSERT INTO glen_test ( type, parent, property )
VALUES ( 'C', 'B', 5);
INSERT INTO glen_test ( type, parent, property )
VALUES ( 'D', 'B', 6);
COMMIT;

```

Thanks for including the code: it makes my job a lot easier.

My solution involves three main steps:

1. Normalizing the Data The table glen_test is not normalized in that a single fact can be stored repeatedly. (E.g., the fact that A is the parent of B appears on two rows, namely the ones with properties 3 and 4). It would be clearer to have one table that just stored the parent-child relationships, and a second table that just stored the direct properties. I'll pretend you've done that by using views.

```CREATE OR REPLACE VIEW  parent_child
AS
SELECT DISTINCT
type,
parent
FROM    glen_test;

SELECT  *
FROM    parent_child
ORDER BY
type;

TYPE       PARENT
---------- ----------
A          null
B          A
C          B
D          B

CREATE OR REPLACE VIEW  property
AS
SELECT  type,
property
FROM    glen_test;

SELECT  *
FROM    property
ORDER BY
type,
property;

TYPE         PROPERTY
---------- ----------
A                   1
A                   2
B                   3
B                   4
C                   5
D                   6

```

Continue to Part 2: Bottom-up hierarchical query...

#### Have a question for an expert?

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

#### Start the conversation

Send me notifications when other members comment.

## SearchDataManagement

• ### ArangoDB 3.5 update improves multi-model database platform

ArangoDB 3.5 accelerates its database platform with improved query performance and enhanced data security capabilities, as market...

• ### GDPR, AI intensify privacy and data protection compliance demands

This guide covers the challenges data management teams face on data protection and privacy, particularly with the rise of GDPR ...

• ### SnapLogic boosts its data integration technology with AI

SnapLogic's latest update for its Intelligent Integration Platform aims to make it easier for users to benefit from data ...

• ### Museums and data: A powerful combination

With more and more museums using data to inform their decision-making processes, visitors are reaping the benefits by enjoying a ...

• ### 5 augmented analytics examples in the enterprise

Here are the top examples of augmented analytics uses that BI vendors support and enable, including data preparation, NLP-based ...

• ### Phocas BI tool proves its value for manufacturers, wholesalers

With its focus on the manufacturing and wholesale distribution industries, Phocas Software has carved out a niche for itself ...

## SearchSAP

• ### How to implement DevOps for SAP Cloud Platform: 4 best practices

A successful implementation of DevOps for SAP begins with understanding several best practices. Here are four to get you started.

• ### SAP S/4HANA Cloud 1908 gets more RPA, embedded analytics

The quarterly release of SAP S/4HANA Cloud includes new RPA and embedded analytics capabilities. One analyst was blunt about his ...

• ### Experts debate whether SAP acquisition of Qualtrics can deliver CX

Ten months after SAP paid \$8 billion for the SaaS experience management platform, experts still differ on what Qualtrics adds to ...

## SearchSQLServer

• ### SQL Server database design best practices and tips for DBAs

Good database design is a must to meet processing needs in SQL Server systems. In a webinar, consultant Koen Verbeeck offered ...

• ### SQL Server in Azure database choices and what they offer users

SQL Server databases can be moved to the Azure cloud in several different ways. Here's what you'll get from each of the options ...

• ### Using a LEFT OUTER JOIN vs. RIGHT OUTER JOIN in SQL

In this book excerpt, you'll learn LEFT OUTER JOIN vs. RIGHT OUTER JOIN techniques and find various examples for creating SQL ...

## TheServerSide.com

• ### Can a left shift in Java cause DevOps developer burnout?

DevOps burnout is more common than you think. Pay attention to the details in your Java shift left to make sure your dev and ...

• ### Microsoft gains instant Java credibility with jClarity buy

Microsoft has acquired jClarity to help optimize its Azure cloud platform to run Java workloads, a coveted target for the now ...

• ### How to install the JDK on Windows and set up JAVA_HOME

You have options when it comes to JDK installations on Windows and Linux. Here are some helpful tips to ensure a proper install ...

## SearchDataCenter

• ### Iran says it's building an AI supercomputer, despite sanctions

In a tweet, Iran said it is building a new supercomputer. Other nations are doing the same because high performance computing ...

• ### IBM Power chip instruction set now open source

IBM opened up its Power server Instruction Set Architecture allowing the open source community to develop more innovative ...

• ### Big Switch updates its Cloud-First Networking portfolio

Big Switch Networks' new products and features aim to help solve issues such as lack of operational consistency, visibility and ...

## SearchContentManagement

• ### Box Shield adds tighter controls for content sharing

New Box security features enable file- and folder-level access control, while admins and security staff get machine-learning ...

• ### Evergage launches Data Warehouse, a BI analytics product

Data Warehouse, Evergage's new BI analytics product, is designed to collect and analyze customer data in an effort to provide ...

• ### Upgrades to Nintex Forms simplifies electronic form creation

The new form designer by Nintex brings user-friendly capabilities to Nintex Forms for both electronic form creation and data ...

## SearchHRSoftware

• ### CEO commitment to upskilling employees may boost HR tech

Top CEOs are promising to train their employees and make sure they are ready for an automating world. Whether the promise is real...

• ### Employee engagement technology not a panacea for HR woes

Employee engagement comes in many shapes and forms, leaving employers to scratch their heads at the best way to motivate their ...

• ### Hiring vendor says gender-based AI bias is pervasive

Gender bias in AI algorithms for recruiting and hiring is a big problem, according to the head of Job.com. With a new hire, the ...

Close