This is what I wish to do using MySQL alone: (without PHP)
PHP Code:
$result=mysql_query("select f2 from t1 where f1=constant limit L"); while( $data = mysql_fetch_row($result) ) mysql_query("update t2 set f4=f4-1 where f3={$data[0]} limit 1"); If you don't know PHP:
select f2 from t1 where f1=constant limit L; for each f2 (from above result) as F: update t2 set f4=f4-1 where f3=F limit 1; How to implement this in MySQL?
Details:
There can be duplicate values in the output of first select, and for each of the duplicates, the update statement will be run. So if value '123' occurs thrice in the output of first select then f4 will be updated to f4-3 where f3=123.
'L' is the number of times the "f1=constant" condition is satisfied in table 't1'; this number is known before hence used as a limit.
limit 1 is used because values in field 'f3' are unique.