How to move one fields data from another field within same mysql database table?

StackOverflow https://stackoverflow.com/questions/21473774

  •  05-10-2022
  •  | 
  •  

Вопрос

In mysql database in user table. I have a field named age but now I would like to move all the contents of age field to newly created field named age_min. How can I do that? Thanks in advance..

Это было полезно?

Решение

You can try this

 UPDATE `user` SET age_min=age;

Другие советы

Simply do:

Update table set age=age_min;

It will replicate the value of the field age to the field age_min

try this qry...

update `user` set `age_min` = `age`;

This Should do:

UPDATE user SET age_min = age;

You could copy all of the data to the new column:

UPDATE `user` SET `age_men` = `age`

OR you could just rename the existing column:

ALTER TABLE `user` CHANGE `age` `age_min` int

(you may have to drop the new column you just created in order to run the above query, if so, do this: ALTER TABLE user DROP age_min

SQL Fiddle:

http://sqlfiddle.com/#!2/dfe84/2

Run this query:

UPDATE `user` SET `age_min` = `age` 
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top