Copy values from one column to another in the same table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thecodeteacher
    New Member
    • Dec 2021
    • 2

    Copy values from one column to another in the same table

    Copy values from one column to another in the same table
  • Varsha1285
    New Member
    • Feb 2023
    • 16

    #2
    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.

    Comment

    • tomypop
      New Member
      • Feb 2023
      • 1

      #3
      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

      Working...