1、UNION在进行表链接后会筛选掉重复的记录,所以在表链接后会对所产生的结果集进行排序运算,删除重复的记录再返回结果。

2、UNION ALL只是简单的将两个结果合并后就返回。这样,如果返回的两个结果集中有重复的数据,那么返回的结果集就会包含重复的数据了。

3、从效率上说,sql union all的执行效率要比sql union效率要高很多,这是因为,使用sql union需要进行排重,而sql union All 是不需要排重的,这一点非常重要,因为对于一些单纯地使用分表来提高效率的查询,完全可以使用sql union All。 
4、删除多条记录,只保留一条

1)delete from tt a
where a.rowid <>(select max(b.rowid) from tt b where b.name = a.name and b.kecheng = a.kecheng and b.score = a.score);

2)delete from 表 where ROWID in (         
select   RID from (select  ROWID as RID, row_number() over (partition by 关键字 order by  rowid) as rn  from 表) a
  where a.rn>1)

相关文章:

  • 2021-08-04
  • 2021-07-11
  • 2022-12-23
  • 2022-03-02
  • 2021-11-29
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-28
  • 2021-12-15
  • 2021-10-03
  • 2022-03-04
  • 2021-07-04
  • 2022-12-23
相关资源
相似解决方案