我正在运行下面的查询从现有表中获取重复的记录。下面是我在做查找重复记录(电话)从两个表mysql选择查询
- 上传CSV
- 加载数据到临时表
- 书面查询检查表通过加入临时表和当前表中已存在具有相同的电话号码重复记录的过程。
我的查询在当前表格中工作正常,最多100,000条记录,但当前表中的实时系统数据多于10,000,000条,因此查询输出超时。
我的查询是
select
tempTbl.id + 1 as SrNo,
`tempTbl`.`phone` as `phone`,
( CASE WHEN count(panelists.id) > 1 THEN
CONCAT(CONCAT('Phone Already Exist with Panelist ID ', panelists.id
,' and Duplidate counts is ',count('panelists.id'))
ELSE
CONCAT('Phone Already Exist with Panelist ID ',' ',panelists.id)
END
) AS reason from `panelists` as `panelists`
inner join `temp` as `tempTbl` on `panelists`.`phone` = `tempTbl`.`phone`
where `panelists`.`panel_id` = ? group by `tempTbl`.`phone`
having tempTbl.phone != ''
我会感激,如果任何帮助的建议,以优化我的查询。提前致谢。
为什么你有写查询的查询?除非您执行它,否则该字符串不会执行任何操作。 – tadman
我在我的代码中执行这个查询,但输出是超时的 – Dnyanesh