I'm writing a python script that searches for duplicate entries in a table in a mysql database using python-mysql-connector. I want the function to output the duplicate entries in a table of customer information. I'm not sure how to store the duplicates and keep track of the index of the item in the table. Should they be stored in a list or set?
import mysql.connector
dbconnect = mysql.connector.connect(host='localhost', user='root', password='wordpass', db='contacts')
cur= dbconnect.cursor(buffered= True)
rows= cur.fetchall()
def find_duplicates(query):
for row in rows:
query= cur.execute ("SELECT id, name, address1, city, postal_code COUNT(*) FROM customer "
"GROUP BY name, address1, city, postal_code HAVING COUNT(*) > 1")
if row in cur.fetchone():
return row
else:
cur.fetchone()