UPDATE `ph3`.`member` SET `name` = (select Sname from member order by rand())
I want to copy Sname to name and I want to re-order column Sname
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First, you are not supposed to be able to do an update to a table that is based on a select from the same table (ie: member).
As for re-ordering the column name, you don’t need to physically change the records as you can
just use an index on the name, in addition to using an ORDER BY clause during any of your queries.
Finally, if you DO based on your update command of random(), there is a STRONG possibility that some of the names will be more than duplicated, and others would be completely lost… The update performs one record at a time. So, if you have names like “A”, “B”, “C”, “D”, “E” and “F”…
And your random() returns “E” first, then record 1 becomes “E” and “A” is now gone, then B gets processed and is randomed with “D”, now “B” is gone and becomes “D”… time for C and it gets random D (ex: original B position) and now another “D”, etc…
If you are trying to create a randomized jumble of names, I would suggest copying the results out to a test table ordering by random, then joining based on the same ID number as newly created to the original ID before it started.