Select MySQL 条与建议的唯一索引冲突的记录

Select MySQL records that conflict with a proposed unique index

我有一组记录要添加唯一索引,但是一些现有记录与该索引冲突,所以我想识别它们并删除它们以便可以对数据施加约束.

有没有一种方法可以根据与唯一索引相矛盾的任何记录编写 SELECT 查询?

示例:

Table 有列

编号 |用户 | question_id |回复 | is_current

我想要一个唯一索引,这样

用户 | question_id |响应 |is_current

不重复。

是否可以 SELECT 所有记录的值集不是唯一的?

显示非唯一:

select user,question_id,response,is_current,count(*) as theCount 
from tablename 
group by user,question_id,response,is_current
having theCount>1