1

我有一张像

表名:电子邮件值

--------------------------------------
| email                    |   value |
-----------------------------------
|  ab@gmail.com            |  A      |
--------------------------------------
|  ab@gmail.com            |  B      |
--------------------------------------
|  ab@gmail.com            |  C      |
--------------------------------------
|  cccc@gmail.com          |  F      |
--------------------------------------
|  dd@gmail.com            |  G      |
--------------------------------------
|  dd@gmail.com            |  A      |
--------------------------------------
|  dd@gmail.com            |  H      |
--------------------------------------

我想在没有第一行的情况下删除同一电子邮件的所有内容。我将如何纠正我的 sql 中的 sql

SQL 应该删除 mysql 中的这 2 行

--------------------------------------
|  ab@gmail.com            |  B      |
--------------------------------------
|  ab@gmail.com            |  C      |
--------------------------------------   

 and also        

 --------------------------------------
|  dd@gmail.com            |  A      |
 --------------------------------------
|  dd@gmail.com            |  H      |
--------------------------------------
4

3 回答 3

3

用它:

DELETE t1 FROM emailvalue t1
LEFT JOIN 
(
  SELECT email, value
  FROM emailvalue
  GROUP BY email
) t2 on t2.email = t1.email AND t2.value = t1.value
WHERE t2.value is null;
于 2013-09-22T07:43:47.620 回答
2
delete t
from your_table t
left join 
(
  select email, min(value) as minv
  from your_table
  group by email
) x on x.email = t.email and x.minv = t.value
where x.minv is null
于 2013-09-22T06:39:43.493 回答
1
ALTER IGNORE TABLE `emailvalue` ADD UNIQUE INDEX(`email`);

MySQL快速从大数据库中删除重复项

MySQL:ALTER IGNORE TABLE ADD UNIQUE,什么会被截断?

于 2013-09-22T06:44:25.690 回答