MySQL 查询重复记录

数据库中如果插入重复记录,需要有效排查出重复结果

方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
SELECT 
	* 
FROM 
	pt_university_institute_staff
WHERE 
	staffId IN (
		SELECT 
			co.staffId 
		FROM (
			SELECT 
				staffId, count(*) AS count 
			FROM 
				pt_university_institute_staff 
			GROUP BY 
				staffId 
			HAVING 
				count > 1
		) co
	);