sql insert into table from select without duplicates (need more then a DISTINCT)

前端 未结 5 536
渐次进展
渐次进展 2021-01-31 11:01

I am selecting multiple rows and inserting them into another table. I want to make sure that it doesn\'t already exists in the table I am inserting multiple rows into.

5条回答
  •  深忆病人
    2021-01-31 11:41

    If you already have a unique index on whatever fields need to be unique in the destination table, you can just use INSERT IGNORE (here's the official documentation - the relevant bit is toward the end), and have MySQL throw away the duplicates for you.

    Hope this helps!

提交回复
热议问题