I have below query in mysql where I want to check if branch id and year of finance type from branch_master
The problem I had with the accepted answer is that create a copy of the whole table, and for me wasn't an option, I tried to execute it but after several hours I had to cancel it.
A very fast way if you have a huge amount of data is create a temporary table:
Create TMP table
CREATE TEMPORARY TABLE tmp_manager (branch_id bigint auto_increment primary key, year datetime null);
Populate TMP table
insert into tmp_manager (branch_id, year) select branch_id, year from manager;
Update with join
UPDATE manager as m, tmp_manager as tmp_m inner JOIN manager as man on tmp_m.branch_id = man.branch_id SET status = 'Y' WHERE m.branch_id = tmp_m.branch_id and m.year = tmp_m.year and m.type = 'finance';