Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从两个字段相同的MySQL表中删除重复项_Mysql_Sql_Duplicates - Fatal编程技术网

从两个字段相同的MySQL表中删除重复项

从两个字段相同的MySQL表中删除重复项,mysql,sql,duplicates,Mysql,Sql,Duplicates,因此,我有一个带有字段ID(AI,主键),ticker,priceDate,price的表 我有一组或多个记录共享相同的priceDate和ticker。对于任何给定的priceDate,每个ticker应该只有一条记录 考虑到priceDate和ticker不是唯一字段,我如何删除这些重复记录?已经发布了此问题的解决方案。非常感谢,我想它成功了。出于兴趣结尾处的x做什么?如果定义子查询,则需要使用别名对其命名。我使用x作为别名。顺便说一句,您需要该子查询,因为MySQL不允许您从正在选择的同一

因此,我有一个带有字段
ID
(AI,主键),
ticker
priceDate
price
的表

我有一组或多个记录共享相同的
priceDate
ticker
。对于任何给定的
priceDate
,每个
ticker
应该只有一条记录


考虑到
priceDate
ticker
不是唯一字段,我如何删除这些重复记录?

已经发布了此问题的解决方案。非常感谢,我想它成功了。出于兴趣结尾处的
x
做什么?如果定义子查询,则需要使用别名对其命名。我使用
x
作为别名。顺便说一句,您需要该子查询,因为MySQL不允许您从正在选择的同一个表中删除。但通过另一个子查询,您可以欺骗MySQL。
delete from your_table
where id not in 
(
  select * from 
  (
    select min(id)
    from your_table
    group by pricedate, ticker
  ) x
)