Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I copy data from one column to another in the same table?

Tags:

sql

Is it possible to copy data from column A to column B for all records in a table in SQL?

like image 566
jonney Avatar asked Jun 10 '11 15:06

jonney


People also ask

How do I copy data from one column to another column in the same table?

UPDATE table SET columnB = columnA; This will update every row. This will also work if you want to transfer old value to other column and update the first one: UPDATE table SET columnA = 'new value', columnB = columnA . Like other answer says - don't forget the WHERE clause to update only what's needed.

How do you copy values from one column to another?

Select the row or column that you want to move or copy. In the cell, click where you want to paste the characters, or double-click another cell to move or copy the data. or press Ctrl+V. Press ENTER.

How do I insert one column data into another column in SQL?

INSERT INTO SELECT Syntax WHERE condition; Copy only some columns from one table into another table: INSERT INTO table2 (column1, column2, column3, ...)

How can I UPDATE one column value to another column in the same table in SQL Server?

In such a case, you can use the following UPDATE statement syntax to update column from one table, based on value of another table. UPDATE first_table, second_table SET first_table. column1 = second_table. column2 WHERE first_table.id = second_table.


2 Answers

How about this

UPDATE table SET columnB = columnA; 

This will update every row.

like image 111
Ash Burlaczenko Avatar answered Oct 14 '22 01:10

Ash Burlaczenko


UPDATE table_name SET     destination_column_name=orig_column_name WHERE condition_if_necessary 
like image 28
dev4092 Avatar answered Oct 13 '22 23:10

dev4092