duplicate row mysql 1

duplicate row mysql

## Find ALL duplicate recods by value (without grouping them by value) ##
# to find the duplicate, 
# replace all instances of tableName with your table name
# and all instances of duplicateField with the field name where you look for duplicates
SELECT t1.*
FROM tableName AS t1
INNER JOIN(
	SELECT duplicateField
	FROM tableName
	GROUP BY duplicateField
	HAVING COUNT(duplicateField) > 1
)temp ON t1.duplicateField = temp.duplicateField
order by duplicateField

Here is what the above code is Doing:
1. The inner query finds all the duplicate values in the duplicateField column.
2. The outer query then joins the table with the inner query to find all the rows that have the duplicate values.

Similar Posts