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

• ### MariaDB X4 brings smart transactions to open source database

Open source database vendor MariaDB updates its flagship platform with new features to enable the convergence of transactional ...

• ### How data lineage tools boost data governance policies

Organizations can bolster data governance efforts by tracking the lineage of data in their systems. Get advice on how to do so ...

• ### New Oracle Enterprise Manager release advances hybrid cloud

Oracle updates its Enterprise Manager platform to version 13.4, bringing new hybrid management capabilities to database users ...

• ### Startup Uplevel targets software engineering efficiency

Startup vendor Uplevel emerged from stealth on Wednesday touting a platform aimed at improving the efficiency of software ...

• ### AtScale's Adaptive Analytics 2020.1 a big step for vendor

AtScale's new update is centered around data virtualization for analytics and marks a significant overhaul of the data ...

• ### How to enhance your data science storytelling

How do you create substantive, compelling stories for business executives from cold, hard numerical data? Experts share their ...

## SearchSAP

• ### SAP S/4HANA migration: Critical advice for moving off ECC

With the end of SAP ECC support looming in 2025, organizations must make some tough decisions. Here's a look at your choices.

• ### New SAP leadership faces big challenges in 2020

Industry analysts discuss SAP's biggest issues in 2020, including how the two new CEOs will guide the company deeper into the ...

• ### SAP Data Hub opens predictive possibilities at Paul Hartmann

When medical supply firm Paul Hartmann AG tested a supply chain analysis system built on SAP Data Hub, it found that it could ...

## 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

• ### Don't ever put a non-Java LTS release into production

Development teams should avoid non-long-term support releases at all costs. Pay attention to the Java release cycle to make sure ...

• ### Public API strategy considerations for enterprise adoption

As organizations look for more cost-effective ways to manage data, an evolving landscape with APIs has made the technology more ...

• ### Ideas on how to hold a successful code hackathon

Want to host a hackathon? Here are some ideas on what a company can do to host an event that solves problems and reenergizes the ...

## SearchDataCenter

• ### Organizations try to predict the effect of 5G infrastructure

With more 5G and IoT devices emerging, admins must prepare their data centers to support low-latency apps and edge computing with...

• ### Top infrastructure and operations technology myths of 2019

Admins are consistently evaluating technology to improve I&O efficiency. Cost, integration and business goals are key components ...

• ### Improve efficiency with server energy consumption tools

Deciding what servers are most efficient for your infrastructure requires research. Hardware-level certifications and web-based ...

## SearchContentManagement

• ### Ex-SAP exec steers Episerver CMS toward digital experience market

Alex Atzberger discusses leaving the helm of SAP's CX platform to become Episerver CEO. Now, Episerver looks to reinvent itself ...

• ### 4 digital transformation terms to know

As technology evolves, businesses have no choice but to follow. Digital transformations are inevitable in order to keep customers...

• ### How to differentiate between CX and DX platforms

CX and DX platforms have similarities in how they manage content to produce interactive experiences, but they aren't the same. ...

## SearchHRSoftware

• ### Top 7 HR trends for 2020 and beyond: The change decade

Because HR requires a balance between the needs of the organization with the needs of employees, it's always been a balancing act...

• ### For insider threat programs, HR should provide checks and balances

Insider threat programs may backfire if employees feel they are intrusive and violate privacy, Forrester Research warns. Making ...

• ### Better HR security could help thwart Iranian cyberattack

HR departments have a broad role to help protect their firms from Iranian cyberattacks. The security efforts include helping with...

Close