Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.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按其他表中的数据排序_Mysql - Fatal编程技术网

Mysql按其他表中的数据排序

Mysql按其他表中的数据排序,mysql,Mysql,我有一张叫“orderby”的桌子 和第二个表数据 我想按orderby tables数据列对数据表进行排序 像这样: +-----------+ | id | ... | +-----------+ | 4 | ... | +-----------+ | 2 | ... | +-----------+ | 5 | ... | +-----------+ | 6 | ... | +-----------+ 我尝试了这个查询:按字段ID从数据顺序中选择*,从orderby中选择

我有一张叫“orderby”的桌子

和第二个表数据

我想按orderby tables数据列对数据表进行排序

像这样:

+-----------+
| id | ...  |
+-----------+
| 4  | ...  |
+-----------+
| 2  | ...  |
+-----------+
| 5  | ...  |
+-----------+
| 6  | ...  |
+-----------+
我尝试了这个查询:按字段ID从数据顺序中选择*,从orderby中选择group_concatdata


但不起作用。

最好的解决方案是在数据表中添加一个列orderby INT UNSIGNED,并使用数字获得正确的顺序

如果需要根据用户进行排序,则必须使用单独的表,其中包含用户id、数据表中的数据id和orderby值

在代码中使用的单个orderby值将不起作用。这可能是可能的,但我认为这将很难实施,而且不会很好地执行

+-----------+
| id | ...  |
+-----------+
| 2  | ...  |
+-----------+
| 4  | ...  |
+-----------+
| 5  | ...  |
+-----------+
| 6  | ...  |
+-----------+
+-----------+
| id | ...  |
+-----------+
| 4  | ...  |
+-----------+
| 2  | ...  |
+-----------+
| 5  | ...  |
+-----------+
| 6  | ...  |
+-----------+