Refers to database tables with a column that is a foreign key to another column within the same table.
Questions tagged [self-referencing-table]
131 questions
3
votes
1 answer
Roll up count in hierarchical table(self referential table)
I Have a table in the below format.This is a self referential table where each record points to its parent record.
NODE_ID PARENT_ID COUNT
1 0 NULL
2 1 NULL
3 2 10
4 2 12
5 0 …

gkarya42
- 429
- 6
- 22
3
votes
0 answers
How to use dumpdata/loaddata in Django with self-referential tables?
I have a Django 1.7 app, developed against sqlite3, and moving to Postgresql. One model table called Place has a parent relation to itself. I used dumpdata to create a .json extract.
When I attempt to use loaddata to read the extract into the…

ugliest
- 101
- 6
3
votes
1 answer
Represent a self reference table in a text tree
I want to represent a self referencing table in a text tree (like TreeView but in text). I have been working on it and I did good so far. The problem is when I go few levels deep in the tree. So far The result is this:
┌──Main Group 1
│ ├──SubGroup…
user915331
3
votes
1 answer
How to limit a self-referencing table in MySQL so a row can't reference itself?
Here is a very basic table to illustrate my question.
CREATE TABLE Customer (
CustID INT,
CustLastName VARCHAR (20),
ReferralID INT,
ADD CONSTRAINT PRIMARY KEY (CustID),
ADD CONSTRAINT FOREIGN KEY (ReferralID) REFERENCES…

Andrew Smith
- 47
- 1
- 4
2
votes
0 answers
Prisma Self referencing tables error on Delete. cannot Cascade
I'm trying to make a CLI application using prisma.
In my schema.prisma file I have a Folder and Phew table to make the "filesystem"
I want to delete all sub-folders and phews when a parent is deleted.
I tried to "Cascade" but it throws an…

mind0bender
- 21
- 4
2
votes
0 answers
Delete Prisma self-referencing (one to many)
I have this prisma schema
model Directory {
id String @id @default(cuid())
name String?
parentDirectoryId String?
userId String
parentDirectory Directory? @relation("parentDirectoryId",…

Filip Pham
- 21
- 1
2
votes
1 answer
Postgres order entries by id, self reference id and date, after every parent, list childs
I have the table orders with the following fields id, updated_at, self_ref_id, and others which doesn't count.
The column self_ref_id is a self reference two an order, one order can have multiple children, a child will not have other children.
I am…

jalanga
- 1,456
- 2
- 17
- 44
2
votes
1 answer
SQL recursion + column concatenation
I've got a self referencing table (in SQL Server):
Page
==========
Id: int
RelativeUrl: nvarchar(max)
ParentId: int -> FK to pageId
Example data:
ID | RelativeUrl | ParentId
===============================
1 | /root | null
2 | /test1 |…

RubenHerman
- 1,674
- 6
- 23
- 42
2
votes
0 answers
How to handle self-reference in Spring Data JPA with Spring Boot 2?
I have a Spring Boot 2 application in which I have the following User entity:
@Data
... JPA and other annotations
class User {
... many fields including Integer id
@ManyToOne(fetch = FetchType.LAZY)
public User createBy;
…

sbsatter
- 591
- 3
- 22
2
votes
1 answer
Ruby on Rails Self Referential Create Action Returning Unknown Attribute Error
I am creating a self referential relationship for services. The idea is to allow you to add a potentially infinite level of sub services to a service, so services can have children, and those children can have children, etc.
To do this I have crated…

Jacob Atwell Parry
- 115
- 3
- 14
2
votes
0 answers
Symfony, Many to many with attributes self referencing
I have an entity Room that has a ManyToMany relationship with itself, and this relationship (RoomLinkRoom) bears an attribute "weight" :
a Room can be linked to several Rooms, with an ordering(weight) value (and potentially other attributes).
The…

Overdose
- 585
- 7
- 30
2
votes
1 answer
Self-referencing many to many relation in Entity Framework Core
I'm using Entity Framework Core (EF) for building models for a project.
Now I want to save companies and their hierachy.
Therefore I have following cases:
A subsidiary company (Child) has any number of children and any number of parents.
A parent…

MCoder
- 39
- 3
2
votes
2 answers
Updating a MySQL table with a self-referencing column
I have a table (simplified) that looks like this:
id | name | selfreference | selfreference-name
------ | -------| --------------| ------------------
1 | Vienna | |
2 | Wien | | Vienna
3 | Виена …

Tench
- 485
- 3
- 18
2
votes
1 answer
Entity Framework 7 self referencing table returning null
I'm using EF 7 (beta6-13679), in an MVC 6 web application (only dnx 4.5.1 due to requiring AD integration), with a database first approach and cannot get a self referencing table to return a value properly, I always get null when running my app,…

ViOTeK
- 23
- 3
2
votes
1 answer
sql - get parentID with or without child in self refrenced table
Here is my table's (events) content. eventID is "primary key" and parentID is "foreign key" with references to events(eventsID)
self referenced table :
eventID eventName parentID appFK
1 evt1 null 2
2 evt2 1 …

cglvli
- 127
- 3
- 10