mysql how to count duplicate records code example

Example 1: find duplicates mysql column

SELECT name, COUNT(*) c FROM table GROUP BY name HAVING c > 1;

Example 2: find duplicate keys in mysql

SELECT col, COUNT(col) FROM table_name GROUP BY col HAVING COUNT(col) > 1;

Example 3: duplicate row mysql

# Duplicate row and change values in the duplicated row
INSERT INTO table (col1, col2, col3)
# manually insert data to the duplicated row
SELECT "new value", "new value", "new value" FROM table
WHERE something...;

Tags:

Sql Example