473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to query designation hierarchy from a table having parent_id structure?

Hi,

I want to generate the organisational structure of my company.I have a table /viewwhich has the emp_id,manager_id and the level_num.The level_num represents the designation level of the employee.So I used a query as:_

select concat(REPEAT('-',a.level_num *5),a.employee_name) as Org_Chart
from ALL_EMPLOYEE_VIEW A
order BY a.level_num ;

This does not create a tree structure but simply arranges the employees according to their levels or designations.However I want the nested set hierarchy that is all the employees be arranged under their manager in a hierarchical manner.Basically I want to create a managerial hierarchy as a organisation chart.How do I do that????????Do I have to query using a stored procedure/function as this is recursive?????If any body has a solution please reply asap.
Dec 11 '09 #1
1 4427
nbiswas
149 100+
Try this

Managing Hierarchical Data in MySQL

There just scroll down and in the Finding the Depth of the Nodes section you will find

Expand|Select|Wrap|Line Numbers
  1. SELECT CONCAT( REPEAT(' ', COUNT(parent.name) - 1), node.name) AS name
  2. FROM nested_category AS node,
  3. nested_category AS parent
  4. WHERE node.lft BETWEEN parent.lft AND parent.rgt
  5. GROUP BY node.name
  6. ORDER BY node.lft;
  7.  
The output is similar to the one you have asked for.

Hope this helps
Dec 15 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dr. zoidberg | last post by:
Hello, I'm creating simple menu. MySQL: +----+-----+----------------------+ | id | sid | Title | +----+-----+----------------------+ | 1 | 0 | Main Menu 1 | 2 | 0 | Main Menu 2 | ...
7
by: Bernard Drolet | last post by:
Hi, I have a table containing many millions of rows. This table has a tree stucture, with the following columns id name parent_id I need to go through the tree, starting from a specific Id,...
4
by: sajid | last post by:
This is a treeview Root -- Cricket1 ---Cricket2 ---sachin --Cricket3 --dravid --FootBALL1
0
by: Ralph Guzman | last post by:
TASK: I have to generate a report with all categories, subcategories and products in database. PROBLEM: I want to write one query that will return: 1. category 2. subcategory: determined by...
1
by: per | last post by:
im not very good at sql but need to query the database to use in my programming script. if the database is just like this id name parent_id 1 A ...
0
by: Mike N. | last post by:
Hello to all: First let me apologize for the length of this question, I've made an attempt to include as much information as is needed to help with the question. I am having problems putting...
7
by: gsoftwares | last post by:
Hi XML Guru, I need to transform flat xml to Hierarchy xml. Can some one help me get started or have a same code with them my flat xml: <rowset> <row>
1
by: Pras | last post by:
SELECT R.Resource_ID, R.ResourceName, R.ResourceGLT_ID, R.ResourceNiku_Id, T.Technology_Code AS TechnologyArea, T2.Technology_Code AS TechnologyArea2, T3.Technology_Code AS TechnologyArea3,...
4
by: robboll | last post by:
When I try to use an append query from an oracle link it takes forever. I am exploring the idea of doing an append action using a pass-through query. If I have an Oracle ODBC connection to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.