相关疑难解决方法(0)

如何在UNION中使用ORDER BY

我想在每个UNION ALL查询上使用ORDER BY,但我无法弄清楚正确的语法.这就是我要的:

(
SELECT id, user_id, other_id, name 
FROM tablename 
WHERE user_id = 123 AND user_in IN (...) 
ORDER BY name
)
UNION ALL
(
SELECT id, user_id, other_id, name 
FROM tablename 
WHERE user_id = 456 AND user_id NOT IN (...) 
ORDER BY name
)
Run Code Online (Sandbox Code Playgroud)

编辑:要明确:我需要两个这样的有序列表,而不是一个:

1 2 3 1 2 3 4 5

非常感谢你!

mysql sql union

7
推荐指数
3
解决办法
1万
查看次数

标签 统计

mysql ×1

sql ×1

union ×1