I wish to insert nested lists into mysql table using Python. I want to insert new rows for new ID values and update certain columns for those with existing ID values. However, for one of these nested lists (Fruits, s[2]) I only want to update these rows within mysql Table if those records are empty! I realise the query I have put only works for new inserting id numbers and does not address updating existing rows. That's where I need help!
s = [[1, 20, 21],[1999, 1998, 1990], ['Apple', 'Pear', 'Bannana']
id = s[0]
yearborn = s[1]
favfruit = s[2]
query = '''INSERT INTO table (PersonID, Year, Fruit)
VALUES (%s, %s, %s)'''
cursor.executemany(query, s)