I have a table with 3 columns:
ID | table | artic开发者_开发知识库le | number 1 2 2 1 2 3 4 4
What I need is a query which checks whether a combination of table and article already exists. For example (table 2 and article 2)
In this case number should be incremented by 1.
So it has to like like this now: 1 2 2 2Otherwise (for example: table 2 and article 5) a new row should be created: 3 2 5 1
Is it possible to do this with 1 statement and how?
Thank you for your help in advance
Check INSERT ... ON DUPLICATE KEY UPDATE Syntax
This may work for you on your DB...
insert into theTable
(ID, table, article, number)
values (3, 2, 5, 1)
where not exists
(select ID
from theTable
where table = 2 and article = 5)
精彩评论