Copy values from one column to another in the same table

Short answer for the code in question is:

UPDATE `table` SET test=number

Here table is the table name and it's surrounded by grave accent (aka back-ticks `) as this is MySQL convention to escape keywords (and TABLE is a keyword in that case).


BEWARE!

This is pretty dangerous query which will wipe everything in column test in every row of your table replacing it by the number (regardless of it's value)

It is more common to use WHERE clause to limit your query to only specific set of rows:

UPDATE `products` SET `in_stock` = true WHERE `supplier_id` = 10

UPDATE `table_name` SET `test` = `number`

You can also do any mathematical changes in the process or use MySQL functions to modify the values.


try this:

update `list`
set `test` = `number`

Tags:

Mysql

Database