Linked Questions

0
votes
3answers
1k views

How to detect level in nested MySQL table? [duplicate]

I have simple child-parent relation by saving parent_id. Is it possible to count which level each entry? My DB looks like this: As You can see from the image, for example the first item relation is: ...
0
votes
2answers
134 views

Hierarcy Query Mysql [duplicate]

I have a table like this... ========================================================================== UID || PARENT ID || SPONSOR ID ===============================================...
1
vote
0answers
27 views

Find entire hierarchy based in all hierarchy levels [duplicate]

I have a table that looks like this: Where EMP has a child SEG and it has a children SUP and so on... What I would like to do is find the full hierarchy EMP>SEG>SUP>DIR>REG>GOP in any of the children ...
15
votes
4answers
50k views

Recursive self joins

I have a comments table, which can be simplified down to this: comments ======= id user_id text parent_id where parent_id is nullable, but might be a key for its parent comment. Now, how can I ...
11
votes
6answers
8k views

What could be causing strange query timeouts between PHP and MySQL?

I am the senior developer on a Software-as-a-Service application used by many different customers. Our software runs on a cluster of Apache / PHP application servers, powered by a MySQL backend. On ...
20
votes
2answers
55k views

MySQL: Tree-Hierarchical query

SUB-TREE WITHIN A TREE in MySQL In my MYSQL Database COMPANY, I have a Table: Employee with recursive association, an employee can be boss of other employee. A self relationship of kind (SuperVisor (...
0
votes
1answer
9k views

Fetch all parents from child id

I created a table with name "vegs" and inserted values just like this. id name parent -------------------------------------- 1 fruits 0 2 Apple 1 3 ...
2
votes
1answer
11k views

Recursive Query in MySQL using stored proceedure and CURSOR

I'm expanding our user/group system to allow for dynamic groups which are made up of other groups members. I have three tables users, groups, and relationships. For simplicity sake, lets say users ...
3
votes
1answer
15k views

Loop through Self JOIN on table until the operand column is NULL completely

For the problem I have a single table which store a Member's ID and His Referee's ID. This is something like a Multi-Level-Marketing plan where you join a company for some tasks and then someone join ...
3
votes
2answers
7k views

Multi level hierarchy relationship

My table design is users (id, username..., parent_id) Data is id username parent_id ------------------------------- 1 | admin | null 2 | reseller 1 | 1 3 | client 1 | 1 4 | ...
0
votes
1answer
7k views

Select all children from infinite parent-child relations

I have a comments table, and rows have parent child relation, which means any comment can have children (responses) and any child itself can also have children (infinitely). All rows are inside one ...
1
vote
1answer
9k views

Get top most parent by nth child id?

Now there is a question we commonly use this technique to maintain the parent child relation i.e we store all the entities in one tables with a parent_id column and all top most parents have 0 in the ...
4
votes
2answers
2k views

How to sort category by path and sort order?

first of all I am sory for my english. My category structure is shown below. My purpose is to get category structure with single query. I sort my table by path and I get category tree. sort_order : ...
2
votes
2answers
6k views

How can I count all children & grandchildren until the 7th level?

I have 3 tables right now 1. members 2. members_parents 3. members_status How can i count the children & grandchildren until to the depth level and separate the count() for the status 0 = ...
0
votes
2answers
4k views

MySQL: How to fetch nth level child menus of a parent menu

I have a menu which is parent of multiple menu items and each child menu has their own child menus. This pattern is continued till 5-6 vertical hierarchy level. I don't want to write a query which ...

15 30 50 per page