Linked Questions

0 votes
3 answers

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: ...
Kin's user avatar
  • 101
0 votes
1 answer

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 ...
Atish's user avatar
  • 1
0 votes
2 answers

Hierarcy Query Mysql [duplicate]

I have a table like this... ========================================================================== UID || PARENT ID || SPONSOR ID ===============================================...
Its Wawan's user avatar
  • 101
1 vote
0 answers

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 ...
Gabriel Ribeiro's user avatar
16 votes
4 answers

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 ...
Josh's user avatar
  • 163
13 votes
6 answers

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 ...
Josh's user avatar
  • 538
23 votes
2 answers

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 (...
Grijesh Chauhan's user avatar
0 votes
1 answer

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 ...
user38957's user avatar
0 votes
1 answer

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 ...
Mehdi Azmoudeh's user avatar
3 votes
2 answers

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 | ...
Ehs4n's user avatar
  • 211
3 votes
1 answer

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 ...
Gufran's user avatar
  • 291
2 votes
1 answer

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 ...
oucil's user avatar
  • 506
2 votes
2 answers

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 = ...
JoeT's user avatar
  • 21
4 votes
2 answers

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 : ...
Farid Movsumov's user avatar
2 votes
1 answer

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 ...
M Khalid Junaid's user avatar

15 30 50 per page