Ask Your Question
0

How can I update multiple rows in a MySQL column from another table in a random manner?

asked 2023-06-05 02:54:36 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-05 02:56:02 +0000

lakamha gravatar image

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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2023-06-05 02:54:36 +0000

Seen: 10 times

Last updated: Jun 05 '23