MySQL Conditional Insert

前端 未结 13 1169
予麋鹿
予麋鹿 2020-11-22 09:51

I am having a difficult time forming a conditional INSERT

I have x_table with columns (instance, user, item) where instance ID is unique. I want to insert a new row

13条回答
  •  醉酒成梦
    2020-11-22 10:18

    Have you ever tried something like that?

    INSERT INTO x_table
    SELECT 919191 as instance, 123 as user, 456 as item
    FROM x_table
    WHERE (user=123 and item=456)
    HAVING COUNT(*) = 0;
    

提交回复
热议问题