Oto zapytanie:
update TestNames t cross join
rndnames r
set t.fname = r.FirstName,
t.lname = r.LastName
where r.ID = floor(1+(rand()*600));
Aktualizuje tylko wiersz w testnames
gdy losowy identyfikator wybrany przez wyrażenie pasuje do identyfikatora w tabeli. Czy id
? wartości w rndnames
wszystkie zaludnione?
Jeśli Twoja tabela nie jest zbyt duża i ma id
, oto inne podejście:
update TestName t join
(select t.*,
(select id from rndnames order by rand() limit 1) as rndid
from testname t
) tr
on t.id = tr.id join
rndnames r
on t.rndid = r.id
set t.fname = r.FirstName,
t.lname = r.LastName;
EDYCJA:
Myślę, że to też zadziała:
update TestNames t cross join
rndnames r
set t.fname = r.FirstName,
t.lname = r.LastName
where r.ID = (select id
from rndnames
order by rand()
limit 1
);