Sql 删除oracle中的重复记录

Sql 删除oracle中的重复记录,sql,oracle,Sql,Oracle,我有一张有两个栏的桌子,id和日期。这里是相同的样本数据 ID DATE 1 01-Jan -14 05.42.23.000000000 pm 1 01-Jan -14 05.06.17.000000000 pm 2 01-Jan -14 05.26.16.000000000 pm 2 01-Jan -14 05.41.20.000000000 pm 3 01-Jan -14 0

我有一张有两个栏的桌子,id和日期。这里是相同的样本数据

ID          DATE
1           01-Jan -14 05.42.23.000000000 pm
1           01-Jan -14 05.06.17.000000000 pm
2           01-Jan -14 05.26.16.000000000 pm
2           01-Jan -14 05.41.20.000000000 pm
3           01-Jan -14 05.21.19.000000000 pm
3           01-Jan -14 05.08.18.000000000 pm
4           01-Jan -14 05.14.17.000000000 pm
4           01-Jan -14 05.17.17.000000000 pm
列ID有需要删除的重复数据,我想保留列日期较大的行

我编写了SQL,但结果不正确

delete from newproducts a
 where a.id in
       (select t.id from newproducts t group by t.id having count(*) > 1)
   and a.date not in
       (select max(t.date) from newproducts  t group by t.id having count(*) > 1);

如何纠正?谢谢

这适用于sql server

delete a from newproducts as a
 where 
exists(
select * from newproducts b
where a.id = b.id and a.date < b.date)
相同或以下内容应适用于oracle

delete from newproducts a
 where 
exists(
select * from newproducts b
where a.id = b.id and a.date < b.date)
尝试使用现有子查询:

delete from newproducts np
    where not exists (select 1
                      from newproducts np2
                      where np2.id = np.id and np2.date > np.date
                     );

不!不再删除重复的问题!我们如何删除重复的问题?