473,770 Members | 5,925 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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_VI EW A
order BY a.level_num ;

This does not create a tree structure but simply arranges the employees according to their levels or designations.Ho wever I want the nested set hierarchy that is all the employees be arranged under their manager in a hierarchical manner.Basicall y 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?????I f any body has a solution please reply asap.
Dec 11 '09 #1
1 4476
nbiswas
149 New Member
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
8476
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 | 3 | 1 | SubMenu 1 of menu 1
7
15315
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, to find all the rows with a specific name.
4
8959
by: sajid | last post by:
This is a treeview Root -- Cricket1 ---Cricket2 ---sachin --Cricket3 --dravid --FootBALL1
0
3258
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 parent_id 3. products in each category or subcategory.
1
3665
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 null <----- root 2 B 1 3 C 1 4 D 1 5 E 2
0
4121
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 together a query to pull out an alternative hierarchical view of my data. The database is implemented under SQL Sever 2000 and I am writing the front end using VB.Net and ADO.net. The following is the portion of my database structure that I am...
7
5402
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
1258
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, R.SeatNo, '' as Location, '' AS Country,
4
7079
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 server OraTest. User: User1 Password: password and I am trying to append all records in table: tblTEST that are code: "abc"
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10057
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.