mysql - Increment a column if a row already exists with the same values -


This is a very difficult one for my SQL-foo.

What I need to do is create a new line (which has 3 columns), as long as a line does not already exist, where both values ​​are the same, and if If it exists, then I have to increase the third value on that line.

Imagine the relationship of two values ​​(A, B) and the third value the strength of relationship (which increases with every unity of that relationship).

Thanks in advance! INSERT ($ a, $ b) in

  A-B (A, B, strength) , 1) Key Duplicate Key Update Power = Power + 1   

Make sure you have a UNIQUE (a, b) or primary key ( A, b) tab restriction

Comments