I have 5 columns a, b, c, d and e.
I want to insert values into first 4 columns and have kept default value as 1 in last column.
I have kept the first 4 columns as primary keys.
If duplicate values are inserted in the first 4 columns, then I want to insert the same values again but with increment in the 5th column.
Eg: if 1,2,3,4 are values for the first 4 columns. then when 1,2,3,4 comes again they need to be inserted as 1,2,3,4 but with fifth column as 2.
I have 5 columns a, b, c, d and e. I want to insert
Share
First remove the primary key and add a unique key instead.
Assuming your table now looks like this
Then you can create a trigger on before insert
This will set field e to the number of occurrences of a,b,c,d
One of the comments above offered a simpler alternative
http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html