长期潜伏者,第一个职位(er?)
我需要根据分布在多个表中的属性删除数据库中的一些重复条目。我就是这么做的,但是我确信还有更好的方法(我绝不是sqlMaven!)。任何指点都很好(当我第二次这样做时,失败了)
我首先从表中获取所有行,按日期排序,然后选择最新的条目(dup1)。然后根据一个值(dup2)将该列表与另一个表匹配。最后,根据两个表中出现的行的id创建一个行列表(dup3)。然后我想从主表中删除第三个临时表中的id。
首先,我创建了一个临时表:
create temporary table dup1
as
select * from
(SELECT hex(media_id) as asset_id, folder_id, name, ingest_date
FROM media
order by ingest_date DESC) as dup
group by name having count(name)>1 and count(hex(folder_id))>1
然后创建第二个临时表:
create temporary table dup2
as
SELECT hex(asset_id) as asset_id, value FROM datavalues where name_id = 103 group by value having count(value)>1;
as
SELECT hex(asset_id), value FROM datavalues where name_id = 103 group by value having count(value)>1;
创建了合并前两个临时表的最终临时表
create temporary table dup3
as
select dup1.asset_id from dup1
join dup2 on dup2.asset_id = dup1.asset_id
然后从介质表中删除dup3中存在的所有资产
DELETE FROM media where hex(media_id) in (SELECT * from dup3);
暂无答案!
目前还没有任何答案,快来回答吧!