cur.execute("""INSERT INTO football.match_events(type, player, time, game_id) VALUES (%s, %s, %s, %s)""", (etype, player_id, time, game_id))
I am completing a project where I scrape and process soccer text commentaries. This INSERT statement is part of a section of code that processes yellow cards. Unfortunately as these commentaries are updated live there are sometimes corrections (although they don't say correction so I can't filter for them). This has led me to have two rows for one booking as it appeared twice in the commentary.
I am looking for an easy way for the SQL statement to check whether all the fields in the query already exist in the table together in a single row. I hope that makes sense.
Replace/on duplicate key updatewill work on any unique key, not only the primary key.UNIQUEconstraint on those four columns (UNIQUE KEY (col1, col2, col3, col4)), then use theINSERT ... ON DUPLICATE KEY UPDATEsyntax when inserting, and MySQL will automatically update the existing row instead if it matches those 4 columns. That's why I linked you to the duplicate.