Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL su chiave duplicata... ottieni un ID esistente?

Puoi aggiungere una terza colonna ModifiedDate e usa quello:

insert into t(id, tag)
    select id, tag
    on duplicate key update ModifiedDate = now();

Ciò assicurerà che si verifichi davvero un aggiornamento e, a sua volta, che LAST_INSERT_ID() restituisce un valore.