I have a table, For example: http://rextester.com/MVG66914
User fills in the fields: name_1
(fill any text) and name_2
(fill 1 or nothing).
If the cell name_1
contains the same text - name_2
cell should be increased by 1.
To look like this: http://rextester.com/FSI28573
I can't set UNIQUE
or PRIMARY
. You can see it on the table examples.
But I can set INDEX
Maybe like this:
ALTER TABLE `table15` ADD INDEX(`name_1`);
ALTER TABLE `table15` ADD INDEX(`name_2`);
For example:
INSERT INTO table14a (id, name_1, name_2) VALUES (2, name_1, name_2)
ON DUPLICATE KEY UPDATE name_2=name_2+1;
But it should need to be increased by 1 automatically, every time, when user creates a new row with identical text in name_1
INSERT INTO productsfp (?) VALUES (?)
ON DUPLICATE KEY UPDATE name_2=name_2+1;
So I tried a variations with DUPLICATE KEY
But it didn't work.
I asked question: MySql how to use UPDATE with HAVING?
But I realized that I was mistaken in forming request. Cuz all values increases by 1, instead of a serial. Then I read MySql documentation about DUPLICATE KEY
and are now stuck in a given issue. Does anyone know how to solve this query?