Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy 1 column to another by mysql query

Tags:

mysql

I have mysql database with following table...

| id | amount | tax | +----+--------+-----+ |  1 | 500    |     | +----+--------+-----+ |  2 | 100    |     | +----+--------+-----+ 

I have to delete amount column but before doing that i want to shift all data of amount row from amount row to tax row. How can it be done using mysql query? Please help.

like image 582
seoppc Avatar asked Jul 26 '11 08:07

seoppc


People also ask

How do I copy a column to another column in MySQL?

To copy from one column to another, you can use INSERT INTO SELECT statement.

How do I transfer data from one column to another column in SQL?

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 I copy data from one column to another?

Move or copy just the contents of a cell 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.


2 Answers

UPDATE mytable SET tax = amount 

after you can remove it

ALTER TABLE mytable DROP COLUMN amount;  
like image 153
Haim Evgi Avatar answered Oct 04 '22 18:10

Haim Evgi


update TABLE_NAME set tax=amount; 

will do.

like image 32
Jerry Tian Avatar answered Oct 04 '22 17:10

Jerry Tian