Answer the question
In order to leave comments, you need to log in
Need advice on MySQL and Php (how to write a query correctly)?
There is a DB approximately on one million records at which 4 fields: name, summ, original, original_already. Initially, the first three fields are filled, you need to write the most time / memory-optimal query that will update the fourth field. For each record, original_already must equal 1 if at least one DB record that has the same name and summ values as the current one has the value original=1. Otherwise, 0 should be written in the field.
The “head-on” solution (two nested loops) will not pass in time. I want the request/script to work for no more than an hour and download no more than 512M.
Answer the question
In order to leave comments, you need to log in
i would try
BEGIN;
create temporary table TMP
as select name, summ
from THETABLE
where original = 1
group by name, summ;
update THETABLE set original_already = 0;
update THETABLE inner join TMP on TMP.name = THETABLE.name and TMP.summ = THETABLE.summ
set THETABLE.original_already = 1
drop table TMP;
COMMIT;
"For each record, original_already must equal 1 if at least one database record that has the same name and summ values as the current one has original=1." Russian is ok? ))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question