我想合并 2 个 select 语句,结果将在记录方面不同,但是我想在第二个 select 语句中省略重复的结果(考虑某些列)
select id,name,[type],[parent] from table1 where [type] = 1
union
select * from table2 // but exclude results from this table where
// a record with the same type and parent exists
// in the first select
我想到过这一点(未测试):
select * from(
select *,rank() over(order by [type],[parent]) [rank] from(
select id,name,[type],[parent] from table1 where [type] = 1
union
select * from table2) t
) a where rank = 1
但这似乎不对,是否有更好的方法从第二次选择中排除重复项?
Edit:
每个项目都可以有附加组件。附加组件有两种创建方式:
1.在表1中专门创建的附加组件
2.公开定义x类型的物品必须有附加组件
第一个 select 获取专门为 Items 创建的插件列表,table2 为所有 Items 创建一个插件列表。现在,如果有专门为某个 Item 创建的插件,将会有一个重复的插件。
try
select * from table1
union
select * from table2
where not exists(select 1 from table1
where table2.parent = table1.parent
and table2.type = table1.type)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)