开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜