为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:DM8
【操作系统】:WINDOWS10
【CPU】:Intel® Core™ i7-10710U CPU @ 1.10GHz 1.60 GHz
【问题描述】*:
select * from (
select 1 ID ,'A' Name
union all select 2 ID ,'A0' Name
union all select 3 ID ,'A1' Name
union all select 4 ID ,'A2' Name
order by ID
) T0
left join
(
select 4 code ,'C' Title
union all select 3 code ,'C0' Title
union all select 2 code ,'C1' Title
union all select 1 code ,'C2' Title) T1
on T0.ID = T1.code
没有 order by T0.ID Mysql数据库可以按T0排序,达梦不能,有什么方法不用order by可以默认按T0排序
Mysql:
达梦:
因为hash join 原因,按照右边的顺序进行连接了 ,修改下sql 即可

select * from (
select 1 ID ,'A' Name
union all select 2 ID ,'A0' Name
union all select 3 ID ,'A1' Name
union all select 4 ID ,'A2' Name
order by ID
) T0
left join
( select 1 code ,'C2' Title
union all select 2 code ,'C1' Title
union all select 3 code ,'C0' Title
union all select 4 code ,'C' Title) T1
on T0.ID = T1.code