Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.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
Mysql Sql按两个表排序_Mysql_Sql_Join - Fatal编程技术网

Mysql Sql按两个表排序

Mysql Sql按两个表排序,mysql,sql,join,Mysql,Sql,Join,我有两个关系:表和表组。一个表可以位于一个表组中,一个表组包含多个表 我需要返回以下输出的select: 表组中sortid为0的所有表->表再次按其sortid排序 所有的桌子都是如此 这在Sql(Mysql dbms)中可能吗 桌子 表组 tablegroup_id, name, notiz, color, customer_id, sort_id, visible '1', 'garten', NULL, '1', '1', '2', '1' '2', 'lounge', NULL, '2

我有两个关系:表和表组。一个表可以位于一个表组中,一个表组包含多个表

我需要返回以下输出的select:

表组中sortid为0的所有表->表再次按其sortid排序

所有的桌子都是如此

这在Sql(Mysql dbms)中可能吗

桌子

表组

tablegroup_id, name, notiz, color, customer_id, sort_id, visible
'1', 'garten', NULL, '1', '1', '2', '1'
'2', 'lounge', NULL, '2', '1', '3', '1'
'3', 'stube', '', '7', '1', '1', '1'
预期产出:

'stube 01' 
'stube 02' 
'tisch 03'
'tisch 04'
'tisch 05'
'tisch 101'
'tisch 102'

在公共
tablegroup\u id
ORDER BY
上的
tablegroups
内部联接
tablegroups
sort\u id
,然后是
table
排序id

SELECT t.name
       FROM table t
            INNER JOIN tablegroups tg
                       ON tg.tablegroup_id = t.tablegroup_id
       ORDER BY tg.sort_id,
                t.sort_id;

示例数据和预期输出将非常有用。让我看看我是否理解您的要求:您希望将
中的所有项目(记录)首先按关联的
表组
排序id排序,然后再按
排序id排序?您没有更好的解释吗?我认为你想要的很简单,但是你表达它的方式很混乱是的,我知道解释很混乱,但不知怎么的,我还是设法理解了我的问题。not给出了想要的结果
SELECT t.name FROM table t ORDER BY t.name更接近结果,即使逻辑仅依赖于一个表。i、 这个问题不够清楚。
SELECT t.name
       FROM table t
            INNER JOIN tablegroups tg
                       ON tg.tablegroup_id = t.tablegroup_id
       ORDER BY tg.sort_id,
                t.sort_id;