Is there MySQL.. INSERT … ON DUPLICATE KEY SELECT?

后端 未结 2 1364
刺人心
刺人心 2021-01-18 12:14

is there a way to do an INSERT but on DUPLICATE KEY instead of an update do a SELECT?

2条回答
  •  深忆病人
    2021-01-18 12:39

    No. You will have to watch for the duplicate key error then issue your SELECT query.

    It'd be quite problematic if that existed since INSERT and UPDATE queries are meant to modify data and SELECT to return a result set. All kinds of drivers/interfaces handle these cases differently for good reason.

提交回复
热议问题