MySQL: Tree-Hierarchical query
- Uninteresting
- Misleading
- Offensive
- Repetitive
- Other

SUB-TREE WITHIN A TREE in MySQLIn my MYSQL Query to Create Table:
I have inserted a set of tuples (Query):
The inserted rows has following Tree-Hierarchical-Relationship:
I written a query to find relationship:
And output is:
[QUESTION] Instead of complete Hierarchical Tree, I need a
Please help me on this. If not query, a stored-procedure can be helpful. I tried, but all efforts were useless! |
|||||||||||||||||||||
migrated from stackoverflow.com Dec 8 '12 at 9:42This question came from our site for professional and enthusiast programmers. |
|||||||||||||||||||||
|
|||||||||||||||||||||
|
I already addressed something of this nature using Stored Procedures : Find highest level of a hierarchical field: with vs without CTEs (Oct 24, 2011) If you look in my post, you could use the GetAncestry and GetFamilyTree functions as a model for traversing the tree from any given point. UPDATE 2012-12-11 12:11 EDTI looked back at my code from my post. I wrote up the Stored Function for you:
It actually works. Here is a sample:
There is only one catch. I added one extra row for the owner
Here is the data
|
|||||||||
|
- Uninteresting
- Misleading
- Offensive
- Repetitive
- Other

|
What you are using is called Adjacency List Model. It has a lot of limitations. You'll be problem when you want to delete/insert a node at a specific place. Its better you use Nested Set Model. There is a detailed explanation. Unfortunately the article on mysql.com is does not exist any more. |
|||||||||
|
protected by RolandoMySQLDBA Dec 11 '12 at 18:38
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
MySQL: Tree-Hierarchical query的更多相关文章
- Mysql错误:Ignoring query to other database解决方法
Mysql错误:Ignoring query to other database解决方法 今天登陆mysql show databases出现Ignoring query to other datab ...
- mysql中slow query log慢日志查询分析
在mysql中slow query log是一个非常重要的功能,我们可以开启mysql的slow query log功能,这样就可以分析每条sql执行的状态与性能从而进行优化了. 一.慢查询日志 配置 ...
- Error NO.2013 Lost connection to Mysql server during query
系统:[root@hank-yoon ~]# cat /etc/redhat-release CentOS release 6.3 (Final) DB版本:mysql> select @@ve ...
- MySQL查询过程中出现lost connection to mysql server during query 的解决办法
window7 64位系统,MySQL5.7 问题:在使用shell进行数据表更新操作的过程,输入以下查询语句: ,; 被查询的表记录数达到500W条,在查询过程中出现如题目所示的问题,提示" ...
- MySQL5.1升级5.6后,执行grant出错:ERROR 2013 (HY000): Lost connection to MySQL server during query【转载】
转载: MySQL5.5升级5.6后,执行grant出错:ERROR 2013 (HY000): Lost connection to -mysql教程-数据库-壹聚教程网http://www.111 ...
- Procedure execution failed 2013 - Lost connection to MySQL server during query
1 错误描述 Procedure execution failed 2013 - Lost connection to MySQL server during query 2 错误原因 由错误描述可知 ...
- MySQL中查询时"Lost connection to MySQL server during query"报错的解决方案
一.问题描述: mysql数据库查询时,遇到下面的报错信息: 二.原因分析: dw_user 表数据量比较大,直接查询速度慢,容易"卡死",导致数据库自动连接超时.... 三.解决 ...
- Lost connection to MySQL server during query,MySQL设置session,global变量及网络IO与索引
Navicat导出百万级数据时,报错:2013 - Lost connection to MySQL server during query 网上一番搜索,修改mysql如下几处配置文件即可: sel ...
- 解决Lost connection to MySQL server during query错误方法
昨天使用Navicat for MySQL导入MySQL数据库的时候,出现了一个严重的错误,Lost connection to MySQL server during query,字面意思就是在查询 ...
- mysqldump导出报错"mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table `file_storage` at row: 29"
今天mysql备份的crontab自动运行的时候,出现了报警,报警内容如下 mysqldump: Error 2013: Lost connection to MySQL server during ...
随机推荐
- Java连接Oracle数据库开发银行管理系统【二、设计篇】
一.总体分析 此系统的实现并不难,但是如何更好的设计出实现方式还是需要更深入的分析,例如:如果再增加其他功能,是不是需要变动的 代码很少,只是直接再增加一点功能就可以了呢?如果使用的不是Ora ...
- Java-继承,多态-0922-04
定义类Human,具有若干属性和功能:定义其子类Man.Woman: 在主类Test中分别创建子类.父类和上转型对象,并测试其特性. 父类: package com.lianxi3; public c ...
- PHP面向对象04_串行化
oop04复习 2014-9-3 10:48:45 要点: --1.克隆对象 --2.__toString( ) --3. __call( ) --4.自动加载类 --5.对象串行化 1.克隆对象以及 ...
- Atitit 判断判断一张图片是否包含另一张小图片
Atitit 判断判断一张图片是否包含另一张小图片 1. keyword1 2. 模板匹配是在图像中寻找目标的方法之一(切割+图像相似度计算)1 3. 匹配效果2 4. 图片相似度的算法(感知哈希算 ...
- SSH+JPA查询两个数据库
1.第一步导包: 1.struts2包: 2.spring包: 3.hibernate包: 4.数据库包: 2.web.xml配置 3.struts2的配置: 1.struts.xml 2.s001. ...
- WPF入门教程系列七——布局之WrapPanel与StackPanel(二)
三. WrapPanel WrapPanel布局面板将各个控件从左至右按照行或列的顺序罗列,当长度或高度不够是就会自动调整进行换行,后续排序按照从上至下或从右至左的顺序进行. Orientation— ...
- 读《编写可维护的javascript》笔记
第一章 基本的格式化 缩进层级:推荐 tab:4; 换行:在运算符后面换行,第二行追加两个缩进: // Good: Break after operator, following line inden ...
- Struts2第一个例子Hello World!
1.首先用eclipse新建一个动态web项目Struts2Demo1: (把Default output floder由build\classes改成WebContent\WEB-INF\class ...
- IE浏览器下常见的CSS兼容问题
目录 [1]宽高bug [2]边框bug [3]盒模型bug[4]列表项bug [5]浮动bug [6]定位bug [7]表单bug 宽高bug [1]IE6-浏览器下子元素能撑开父级设置好的宽高 & ...
- HT for Web自定义3D模型的WebGL应用
有不少朋友询问<HTML5 Web 客户端五种离线存储方式汇总>文章例子的3D表计模型是如何生成的,这个例子是通过导入3dmax设计好的表计模型,然后通过obj格式导入到HT for We ...
