MySQL copy data from one column to another column
We will show you copy data from one column to another column in the same table by MySql UPDATE Command.
We have a table sortable with blog_id, blog_title, blog_desc, blog_order Columns and we want to copy value of column blog_id into column blog_order.
In the above Image you can see that blog_order column have Null value. Now we want to copy blog_id column values to blog_order column. For achieve this result we execute below MySql Query
UPDATE `sortable` SET `blog_order` = `blog_id`
After run the above query. Result show in below Image
Now you can see that column blog_id all values inserted blog_order column
If we want to not copy some values of column into another column. We can use UPDATE with some condition. Here we show example in which blog_id column value 1 not copy in blog_order column.
UPDATE `sortable` SET `blog_order` = `blog_id` WHERE `blog_id` != 1
In above Image you can see column blog_order first row value not updated.
I hope this article helps you.
Thanks for visiting Inflay.com .