I'd like to update my table so that rows that share values (in the same columns) get tagged as such.
Example table definition:
CREATE TABLE `MyTable` (
`id` int NOT NULL ,
`a` varchar(10) NOT NULL ,
`b` varchar(10) NOT NULL ,
`state` tinyint NOT NULL ,
PRIMARY KEY (`id`)
) ;
I'd like to update "state" of every row that share values in the same column. So if row one has "a=AAAA" and row two has the same value for "a", both should get updated.
I tried this but it's too slow (not faster then doing it in Java using JDBC):
declare mycursor cursor for select id, a, b from mytable;
open mycursor;
repeat
fetch mycursor into idid, aa, bb;
update mytable set state=1 where (a=aa, b=bb)
until done end repeat;
close mycursor;
Any ideas to make this way better? I haven't done any decent SQL in years.