MySQL 去重SQL

王金龍發表於2017-12-05
DELETE
	t_trace_register
FROM
	t_trace_register,
	(
		SELECT
			min(id) AS id,
			user_id
		FROM
			t_trace_register
		GROUP BY
			user_id
		HAVING
			count(*) > 0
	) AS t2
WHERE
	t_trace_register.user_id = t2.user_id
AND t_trace_register.id > t2.id
複製程式碼

相關文章