为什么union中的order by 会失效?

GoAndSeek GoAndSeek 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
(select suites.description as description,suites.id as id,users.ldap_uid as owner, clusters.name as cluster,

clusters.id as _clusters_id,suites.time_limit as _time_limit,suites.diff_folder as _diff_folder,
suites.recurrence as _recurrence, suites.ini_file as ini, suites.parent_group_id as

_parent_group_id,suite_groups.name as _parent_group_name,
concat_ws(' ',app_names.name, app_ver_major.ver_major, app_ver_minor.app_ver_minor) as application,
app_ver_major.id as _app_ver_major_id, app_ver_minor.id as _app_ver_minor_id, app_names.id as

_app_names_id, suites.baseline_folder as baseline
from suites join applications, app_names, app_ver_major, app_ver_minor, clusters, users,suite_groups on users.id =

suites.owner_id and applications.id = suites.application_id
and app_names.id = applications.app_name_id and app_ver_major.id = applications.app_ver_major_id and

app_ver_minor.id = applications.app_ver_minor_id and clusters.id = suites.cluster_id
and suites.parent_group_id = suite_groups.id
where suites.id =3194
order by suites.id desc)
union
(select "fill",suites.id as id,"fill", "fill", "fill" ,"fill","fill", "fill", "fill", "fill","fill",

"fill", "fill", "fill", "fill", suites.baseline_folder as baseline

from suites
where suites.suite_parent_id=3194 and suites.baseline_folder<>""
order by suites.id desc)

一个问题是在union中的order by suites.id desc失效了,输出的结果没有降序(若单独一个查询则成)
另外,不知道用"fill"填充以维持2个查询列匹配,这种做法是否能适用所有数据库,是否是标准的? 多谢了!
...全文

相关推荐

union all与order by用法

union all与order by用法,并详细举例,oracle pl/sql

hbj0704

MySQL利用UNION连接2个查询排序失效详解

概述 UNION 连接数据集关键字,可以将两个查询结果集拼接为一个,会过滤掉相同的记录 UNION ALL 连接数据集关键字,可以将两个查询结果集拼接为一个,不会过滤掉相同的记录 今天在接到一个需求的时候使用了UNION进行查询后发现,如果两个查询分别使用ORDER BY后拼接居然无法成功排序,经过了好一番折腾,记录下 表结构及数据 -- 创建表 CREATE TABLE test_user ( ID int(11) NOT NULL AUTO_INCREMENT, USER_ID int(11) DEFAULT NULL COMMENT '用户账号', USER_NAME var

weixin_38529397

MySQL中union和order by同时使用的实现方法

下面小编就为大家带来一篇MySQL中union和order by同时使用的实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

weixin_38686187

Mysql联合查询UNION和Order by同时使用报错问题的解决办法

很多朋友刚使用联合查询UNION的时候常常会理所当然的将联合查询理解为把没一个子查询的结果集组合成一个大的结果集

weixin_38702417

MySQL中Union子句不支持order by的解决方法

主要介绍了MySQL中Union子句不支持order by的解决方法,结合实例形式分析了在mysql的Union子句中使用order by的方法,需要的朋友可以参考下

weixin_38704284
评论 6
收藏 已收藏
分享
返回顶部
GoAndSeek
基础和管理 17,380 成员 95,111 内容