Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 从邻接列表中选择,并从下到上排序_Sql_Mysql_Adjacency List - Fatal编程技术网

Sql 从邻接列表中选择,并从下到上排序

Sql 从邻接列表中选择,并从下到上排序,sql,mysql,adjacency-list,Sql,Mysql,Adjacency List,鉴于下表结构: CREATE TABLE IF NOT EXISTS `roles` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(32) NOT NULL, `description` varchar(255) NOT NULL, `parent` int(11) unsigned DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `uniq_nam

鉴于下表结构:

CREATE TABLE IF NOT EXISTS `roles` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(32) NOT NULL,
  `description` varchar(255) NOT NULL,
  `parent` int(11) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniq_name` (`name`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
是否有可能以这样一种方式查询它:首先返回子对象(从下到上)

我们的目标是将它们加载到Zend_Acl的
addRole
方法中,该方法要求在添加子级之前添加角色

我目前的方法是次优的(可能是错误的),需要2个查询。一个用于获取所有叶节点(其中父节点为NULL),另一个用于获取父节点按父节点排序的叶节点(DESC)


任何帮助都是非常感谢的。

ORDER BY(parent不为空)ASC,parent DESC

下面是我刚才给出的一个基于角色的安全答案,可能会有所帮助:

全文如下:

1,  user,       Login privileges, granted after account confirmation, 17
2,  admin,      Administrative user, has access to everything.,       NULL
15, unverified, Users who have not validated their email address,     NULL
16, verified,   Users who have validated their email address,         NULL
17, guest,      A guest role, an anonymous visitor with no account,   NULL
18, moderator,  Role for doing staff duties,                          1