Mysql Hierarchial Query
Dear Experts,
Here is my table
Quote
mysql> SHOW CREATE TABLE empl_tmp;
+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| empl_tmp | CREATE TABLE `empl_tmp` (
`tmp_id` int(11) NOT NULL AUTO_INCREMENT,
`tmp_from_empl_id` int(11) NOT NULL,
`tmp_to_empl_id` int(11) NOT NULL,
`tmp_status` tinyint(4) NOT NULL DEFAULT '1',
PRIMARY KEY (`tmp_id`)
) ENGINE=MyISAM AUTO_INCREMENT=148 DEFAULT CHARSET=latin1 |
+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
Here is my table data,
Quote
+--------+------------------+----------------+------------+
| tmp_id | tmp_from_empl_id | tmp_to_empl_id | tmp_status |
+--------+------------------+----------------+------------+
| 1 | 11689 | 31247 | 1 |
| 2 | 31247 | 11700 | 1 |
| 3 | 11700 | 11689 | 1 |
| 4 | 11650 | 11655 | 1 |
| 5 | 11655 | 11650 | 1 |
+--------+------------------+----------------+------------+
I need the output as,the input will be empl_id= 11689...Then need to list the below mentioned records
Quote
+--------+------------------+----------------+------------+
| tmp_id | tmp_from_empl_id | tmp_to_empl_id | tmp_status |
+--------+------------------+----------------+------------+
| 1 | 11689 | 31247 | 1 |
| 2 | 31247 | 11700 | 1 |
| 3 | 11700 | 11689 | 1 |
+--------+------------------+----------------+------------+
Thanks,
Murali.V
Subject
Written By
Posted
Mysql Hierarchial Query
November 22, 2014 03:30AM
November 22, 2014 09:47AM
November 22, 2014 12:09PM
November 22, 2014 12:48PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.