为什么union中的order by 会失效?
(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个查询列匹配,这种做法是否能适用所有数据库,是否是标准的? 多谢了!
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
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
MySQL中union和order by同时使用的实现方法
下面小编就为大家带来一篇MySQL中union和order by同时使用的实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Mysql联合查询UNION和Order by同时使用报错问题的解决办法
很多朋友刚使用联合查询UNION的时候常常会理所当然的将联合查询理解为把没一个子查询的结果集组合成一个大的结果集
MySQL中Union子句不支持order by的解决方法
主要介绍了MySQL中Union子句不支持order by的解决方法,结合实例形式分析了在mysql的Union子句中使用order by的方法,需要的朋友可以参考下


基础和管理
