mysql根据某一字段去除重复数据

SQL如下:

删除表crawl_simple_poi_all_ids_copy1  中 poi_id字段值重复得数据

#=======sql1:

DELETE FROM crawl_simple_poi_all_ids_ovr
WHERE
	poi_id IN (
		SELECT t.poi_id FROM
			(
				SELECT
					poi_id
				FROM
					crawl_simple_poi_all_ids_ovr
				GROUP BY
					poi_id
				HAVING
					count(1) > 1
			) t
	)
AND id NOT IN (
SELECT dt.mindeptno FROM
	(
		SELECT
			min(id) AS mindeptno
		FROM
			crawl_simple_poi_all_ids_ovr
		GROUP BY
			poi_id
		HAVING
			count(1) > 1
	) dt
)

#=======sql2:

DELETE 
FROM
	crawl_simple_poi_all_ids_ovr AS ta 
WHERE
	ta.id <> (
SELECT
	t.maxid 
FROM
	( SELECT max( tb.id ) AS maxid FROM crawl_simple_poi_all_ids_ovr AS tb WHERE ta.poi_id = tb.poi_id ) t 
	);

#crawl_simple_poi_all_ids_ovr   为表名
#poi_id重复字段
#id唯一字段

 

你可能感兴趣的:(mysql)