Questions tagged [hierarchy]
For issues relating to arranging items into ordered levels.
157
questions
2
votes
1answer
65 views
Org chart CTE with exact index but plan shows expensive sort node
I've got a moderately large table (148 million rows) that's got pretty common org chart attributes to it. Names are changed, but it's the same idea. I was thinking of adding a hierarchyid column to ...
3
votes
1answer
50 views
Ordering CONNECT BY siblings
I have an hierarchical query that uses CONNECT BY:
select
wonum,
parent,
classification,
classstructureid,
division,
worktype,
status,
glaccount,
fircode,
...
1
vote
1answer
40 views
Relationship design for areas, managers and general manager
Given some specifications I need to design a database for an organization. One of the parts has to do with areas. In the organization there are different areas, each area has a boss, and there is also ...
0
votes
1answer
27 views
How to improve poor performance with two joined CTE expressions on hierarchical data?
I have a table of hierarchical data where I want to select entries that, 1) only include matches that are descendants of a given parent, and 2) returns the full hierarchical path of the matched ...
1
vote
0answers
39 views
Recursively list dependencies / references of a stored procedure
I'm trying to import a subset of our production dump with impdp for our local development database running on Oracle XE.
To find out what other objects I have to import for a particular stored ...
0
votes
1answer
21 views
Aggregating nested set models with field constraints
I have a table built on the nested set model that basically records transactions of different natures (defined by the field idx):
pk lft rgt idx value
1 1 30 2783 20402.710000
2 ...
1
vote
2answers
135 views
Hierarchical data using closure table, how to ensure that a column is unique within the parent node?
I store hierarchical data in a Node-table, combined with a closure table (NodeClosure). Each node has a column "name" that should be unique among the sibling nodes (link to parent-Node + ...
0
votes
0answers
96 views
ISA-to-Table & Primary Key for Relationship Type
1).ER DIAGRAM TO RELATIONAL DATABASE
2).CAN A RELATIONSHIP TYPE HAVE AN ATTRIBUTE WITH A PRIMARY KEY?
Can a relationship type have a primary key (primary attribute), like in the picture below? Can '...
2
votes
3answers
120 views
Foreign key reference to column that is no primary key
I know, foreign keys should uniquely identify rows and therefore reference a primary key.
However, consider my example: There are 4 pre-defined categories, and for some combinations of values for ...
0
votes
1answer
183 views
Pattern for copying hierarchical data from one table to another?
Imagine a table with three columns: an ID primary key, a nullable ParentID referencing the ID column on that same table, and a TreeID to indicating the records that make up a particular tree. A basic ...
-1
votes
1answer
61 views
SQL Variables inside SELECT query in a function
MariaDB 10.3.14
I have a function that generates the root id in a hierarchy:
The function is this:
CREATE FUNCTION `getRootId`(GivenID INT) RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE ch INT;
...
-1
votes
1answer
43 views
MS SQL 2017: hierarchy tree - get quantity of last level components
There's a table of items with their components. Components depth vary i.e. some items may have one level of components other may have tens nested components. I need to get quantinty of last level ...
1
vote
1answer
45 views
Generate hierarchical path
I have a classstructure table:
create table classstructure (classstructureid number(8,0), classificationid varchar2(25), parent number(8,0));
insert into classstructure(classstructureid, ...
1
vote
1answer
143 views
Database Design - hierarchical structure
We are trying to redesign a database that currently holds thousands of parameters for different datatypes and currently has a flat data structure.
We generate XML files from the database, which our ...
0
votes
1answer
18 views
Is there such a thing as an OLAP cube that can change the number of levels in a hierarchy without having to be rebuilt?
The current analytics solution that my team works with cannot handle changes in the structure of one of its hierarchies. If a new level or branch is added, then the entire domain must be first backed ...
0
votes
0answers
42 views
How to retrieve all children of a parent record?
I have one MySQL table with this columns:
id
father
son
street
city
I want to obtain all descendants of a father recorded, how I can do this?
I tried this:
WITH RECURSIVE filhos AS (
select login, ...
0
votes
0answers
586 views
Sql subquery for nested parent child data
I have two tables , on parent table (categories ) and child table (features).. I have this query
select c.* ,
(select GROUP_CONCAT(f.featuresId , f.featuresTitle )
from ...
2
votes
1answer
62 views
How to select id of father from the child id recursively
I have in the field cod_categorizacao_pai the ID of the father, and I need to mount a select that just enter an ID and it will list the paternal IDs of this ID until it reaches the parent of all. How ...
2
votes
1answer
930 views
How to query all entities associated with all children (recursive) of a node in SQL?
This question is about SQL in general. Answering specifically for MySQL would be helpful but not necessary.
Ok, I’m having trouble putting this into words… so bear with me.
Say I have a tree of ...
1
vote
0answers
226 views
Worked example of closure tables with from and thru dates
I work for a law enforcement agency, and have been asked to create a way of storing the chain of command in such a way that its structure can be viewed at any point in time, not only as it is now.
...
3
votes
3answers
2k views
SQL Server CTE Bottom to Top Recursive with Where clause
I have an Employee Table with an EmployeeId, ManagerId and a Name field.
The goal is to make a recursive With fetching all the rows from an employee to the top manager (ManagerId is null).
I found ...
4
votes
3answers
67 views
How can I pass on a value in the hierarchy based on the value of the parent using an hierarchial query?
I have a table with categories and another table with a discount for categories per user:
create table category
(
id NUMBER NOT NULL,
parent_id NUMBER,
name nvarchar2(255),
PRIMARY KEY( id)
)...
0
votes
1answer
250 views
Advantages of a hierarchical schema for private chat
This post claims that
All modern chatting interfaces, without exception, implement a
hierarchical and a not-chronological schema for chat.
It also links another post which gives an example ...
3
votes
2answers
2k views
Parent Child Relation in same Table . Select Query to get only parent records and Records not comes under parent child relation
I have a table with Parent-Child Relation in the same Table. Some Sample Data
id │ name │ parent │ is_active
════╪══════════════════════╪════════╪═══════════
1 │ Company A ...
3
votes
1answer
1k views
How to do hierarchical queries without CTE tables or recusive queries in Snowflake? (parent, child relationships)
I have several tables in Postgres that we are migrating to Snowflake. Some of these table are hierarchical (a foreign key point to the same table), normally to query this data I use CTE tables and/or ...
1
vote
1answer
723 views
Oracle hierarchical query: aggregate over each node's descendants, give results in tree pre-order
Given hierarchical data, for each item I need to get the sum of a column over the sub-tree rooted at the item, and I need the results in pre-order.
Example: for the data
employee_id | manager_id | ...
1
vote
1answer
774 views
How make recursive json on mysql
my table looks like
CREATE TABLE `test_comments` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int(10) unsigned DEFAULT NULL,
`test_id` int(10) unsigned NOT NULL,
`user_id` int(...
1
vote
0answers
283 views
How to get the hierarchy of particular employee using JPA spring boot?
I am trying to find a way to get the employee hierarchy in an organization using JPA and Spring boot.
The problem is similar to the following link
Similar Data Model
If A reports to B and B reports ...
2
votes
0answers
51 views
Design for a child to have a single parent `A` OR `B` with FK cascade constraint?
I'm assuming this is not possible with PK and FK...
Let's say I have tables A, B, and C.
A and B are "parents", and B and C are "children"
A is the root
B can be the child of either A or B
C ...
1
vote
0answers
66 views
Scalable way to manage aggregated statistics over time in hierarchy?
I'm using a closure table (Postgres through Django) to roll up stats through a hierarchical tree. When a node that is 10 layers deep has a value that increases, each parent's sum total of that value ...
-2
votes
2answers
112 views
What's the best way to represent an event from a system in a chat?
Conversations
--------------
id
Messages
--------------
id
conversation_id
user_id
reply_to_id
content
created_at
I was looking at this question and I had a question: How to build a table for a ...
1
vote
0answers
55 views
Nested set model in higher dimensions
The nested set structure is well-known and involves using left and right values to denote the relative heirarchy of nodes on one axis.
Is there a generalization of this structure to higher dimensions?...
8
votes
3answers
17k views
Parent/Child Relationship Table Design - What's The Best Practice?
I have a single table for storing 'Tasks'. A task can be a parent and/or a child.
I use the 'ParentID' as the FK referencing the PK on the same table. It is NULLABLE, so if it is NULL it does not have ...
2
votes
1answer
141 views
Correct way to join row in parent table to row in one of several children tables
I have a parent table product, and several children tables like phone, tablet, smartwatch etc. The parent and children have 1-1 relationship. This means that for every row in parent table, there will ...
1
vote
1answer
38 views
How to add foreign key in a table where column value can come from two different tables?
I have three tables
create table main_comments (
id serial primary key,
comment text not null
);
create table sub_comments (
id serial primary key,
main_id integer not null,
comment ...
3
votes
2answers
481 views
Get all descendants from 3 hierarchical tables
I have the following tables within a database:
+-------------+ +-------------+-------------+ +---------------------------+
| project1 | | project2 + | project3 ...
0
votes
1answer
213 views
Bypass truncated data type error in `CREATE TABLE AS`
I am attempting to recreate the code from this excellent tutorial in MariaDB 10.2 to try and build nested sets from an existing adjacency list. (The goal being to ingest changes to the adjacency list ...
3
votes
2answers
63 views
Nullable, dependent attributes
I'm designing a database for students. Computer science students here in Switzerland can decide between different specializations, e.g. application development, system engineering etc.
There are ...
5
votes
1answer
2k views
Condition in WHERE vs condition in CONNECT BY
Can anyone explain to me the difference between the following two queries? Even though they seem the same the results are different.
select concept.concept_id, concept.PARENT_ID
from ...
3
votes
1answer
101 views
How to store hierarchical dimension for timeseries data
I have a requirement to store data about a load of Searches. Each time someone searches we want to record it for analyzing later on.
As part of the search the user can select one or more Categories ...
1
vote
1answer
91 views
Select top-most folder in a hierarchy by given criteria in MySQL
I'm using MySQL (5.7.20) to store a folder hierarchy. Each folder is stored together with all direct and indirect parents including the distance. As an example, the following folders
A
+- B
+ C
...
0
votes
1answer
172 views
Procedure for tree view [duplicate]
I trying to fetch data form database which is have 3 column unique_id, parent_id & node_name, but this query (Given in below) is return only two rows.
Condition: every parent has two child.
DROP ...
5
votes
2answers
35k views
Parent Child Relation in same Table
I have a table storing parent/child records as such:
+-------+------------+---------+---------+------------+-----------+
|custid | custname | deptid | company |parentcustid| enrolled |
+=======+==...
0
votes
1answer
678 views
Design: Postgres, Parent to Child / Child to Parent / Child to Child | JSONB
I am very new to database design. I am hoping for suggestion or solutions for a feature I am working.
Note: We are majorly using JSONB type in Postgres
Feature:
I have a orders table which would ...
3
votes
1answer
252 views
Is a Self-defining Table of Domains Normalized?
I don't really know the official name of what I've made but it can't be the first time this has been made, so apologizes up front for not knowing every term.
My question, is a table as outlined below ...
0
votes
1answer
304 views
Why does Oracle yield multiple levels per row in this hierarchical query?
I'm trying to reproduce the first simple example from this tutorial.
However, I don't understand why I get so many rows back. I would expect that 1 reports to 2 only at level 1 and not at level 2 as ...
2
votes
2answers
7k views
How to organize binary tree in database? [closed]
Here is the situation, I need to organize some users like an binary tree to explain organization workflow, but organization can change.
Here is how its look like:
1
/ \
2 ...
2
votes
0answers
460 views
Auto-update hierarchyid of multiple records in INSTEAD OF UPDATE trigger
I am working with an INSTEAD OF UPDATE trigger, where I have to calculate / re-calculate the hierarchyid of a row based on another column value. Thus far, I have it working. The problem that I run ...
0
votes
1answer
254 views
Recursive Seller Account with Balance
I need to build a database for managing Short Messaging Service (SMS).
In this I have 2 types of users
Reseller
Must have starting SMS balance for example: 1,000 - credit table
He can sell ...
3
votes
2answers
4k views
Get Nested/Hierarchical Data from SQL Table
I have a table relationship between 'Tag' and 'Task'. It is M:M. The relationship is mapped in the table 'TagTaskMapping'.
The TagAssignment table stores the relationship between a Tag and a date. So ...