开发者

How to insert data only if data doesn't already exist in MYSQL?

开发者 https://www.devze.com 2023-01-01 21:08 出处:网络
This is what I\'m doing right now: Execute a query and check if the date to be inserted already exists in a

This is what I'm doing right now:

Execute a query and check if the date to be inserted already exists in a table.

If date doesn't exist:

Another query wil开发者_如何学Gol insert the date into the table.

How can these two query be combined?


IF NOT EXISTS (SELECT * FROM X WHERE A=B)
    INSERT INTO ...


Taken from here:

INSERT IGNORE INTO Table (EmailAddr) VALUES ('test@test.com')


you can put the two statements together into a stored procedure

0

精彩评论

暂无评论...
验证码 换一张
取 消