Copy values from one column to another in the same table
Copy values from one column to another in the same table
Collapse
X
-
Tags: None
-
Let me explain this with an example Suppose there is table named STUDENT and it has 2 columns Student_id and roll_no and you want to cop data of roll_no to Student_id.This is the syntax
UPDATE STUDENT SET Student_id=roll _no;
This query will update all the data of roll_no to Student_id column. -
How can I copy data from one column to another 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.Comment
Comment