copying data from one column to another with sql

2019-03-08

 | 

~2 min read

 | 

214 words

If you need to copy all data from one column to another column in SQL, use the UPDATE method.

If it’s a simple copy for copy, without conditionals, across tables, etc., the query is simply:

UPDATE `table_name` SET
 `destination_column` = `source_column`

The full set of options :

[ WITH [ RECURSIVE ] with_query [,] ]
UPDATE [ ONLY ] table_name [ * ] [ [ AS ] alias ]
    SET { column_name = { expression | DEFAULT } |
          ( column_name [,] ) = [ ROW ] ( { expression | DEFAULT } [,] ) |
          ( column_name [,] ) = ( sub-SELECT )
        } [,]
    [ FROM from_list ]
    [ WHERE condition | WHERE CURRENT OF cursor_name ]
    [ RETURNING * | output_expression [ [ AS ] output_name ] [,] ]

Full documentation on UPDATE in Postgres for the current version (11), is here: PostgreSQL: Documentation: 11: UPDATE

For more discussions, see StackOverflow:

Turns out that at least in the simplest case, Postgres and MySQL are identical.



Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!