IF exists, update, ELSE, insert? Need query help
I have an importer tool that currently executes queries in batches of 100 at a time using "INSERT IGNORE" with a couple columns set as unique. All is working well.
However, I want to modify it so that, if a record already exists (based off the unique columns), only update a couple of columns rather than replace the entire row, resulting in a new PK value. It essentially needs to update a portion of the row is it exists. If not, insert as normal. INSERT IGNORE will just ignore it obviously, and REPLACE INTO adds a new row - I just need to update the existing one.
How can I do this without incurring too much overhead? It works quite fast right now. My query looks like this:
insert ignore into (col1, col2, col3) values (1,2,3), (4,5,6), (7,8,9)...etc...
How can I modify this query with the logic stated above, and with the least overhead? Thanks!