Several Updates from a select RAND

Asked

Viewed 57 times

1

UPDATE `tabela` SET `Relacionar_A` =
(SELECT `Relacionar_A` FROM `tabela` WHERE `Relacionar_A`='' ORDER BY RAND() LIMIT 2)

I can do the update single, only 1 record from the select.

What I would like - and that I did not give a search (probably did not use the best keywords so I am here) - is to know how I can make a update multiple, several records from this mine select.

The idea is to draw contacts and choose the number of contacts to be drawn and the person to whom this contact will be related.

To draw I use:

SELECT * FROM `tabela` WHERE `Relacionado_A`='' ORDER BY RAND() LIMIT $tQuantidade

And do the update of all these random records at once with the Related Person to these records.

  • Could you put an example of the data before and after the query? It would help you understand what you want

  • the user will set the amount of records ($tQuance) to be drawn and the contributor to whom these records will be related ($tRelated_A)... I want to take random bank records to relate to the collaborator and update several records at once... at the time what I got closest to anything was this UPDATE tabela SET Relacionar_A="$tRelacionado_A" WHERE Relacionar_A = (SELECT * FROM tabela WHERE Relacionar_A='' " ORDER BY RAND() LIMIT $tQuantidade), but I can only do this for a record, not in several ways...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.