You can use the following SQL query to update multiple rows in a MySQL column from another table randomly:
UPDATE table1
SET column1 = (
SELECT column2
FROM table2
ORDER BY RAND()
LIMIT 1
);
In this query, table1
is the table in which you want to update the data, column1
is the column you want to update, and table2
is the table from which you want to select the data randomly.
The ORDER BY RAND()
clause is used to sort the data in table2
randomly, and the LIMIT 1
clause is used to select only one row from table2
.
Note: It's important to ensure that both tables have a common key that can be used to match the rows.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-05 02:54:36 +0000
Seen: 11 times
Last updated: Jun 05 '23
How can multiple queries be merged into a single stored procedure in MySQL?
What does "waiting for handler commit" mean in relation to the slow writes experienced in MySQL 8?
How can Spring Boot and Mysql be utilized for CRUD operations?
How can I use sqlalchemy to merge JSON within a column of mysql?
Retrieve all rows in which two IDs appear for the first time.
What are the benefits of choosing sqlalchemy.types instead of sqlalchemy.dialects.mssql?