-3
+--------+------+-------+-------+
| C1     |  C2  |  C3       C4  |
+--------+------+-------+------+
| Value1 | 1234 |  9876 |   A1  |
| Value2 | 1234 |  9876 |   A1  |
| Value3 | 1234 |  9876 |   A1  |
| Value4 | 1234 |  9876 |   A1  |
| Value1 |      |       |   B1  |
| Value2 |      |       |   B1  |
| Value3 |      |       |   B1  |
| Value4 |      |       |   B1  |
+-------+------+-------+------- +

I have a MySQL table with the above structure.I want to update the last four rows for column C2 & C3 with the same data as in the first 4 rows of column C2 & C3.This update has to be done using the same table multiple column data.

How can I achieve this?

Strawberry
  • 33,750
  • 13
  • 40
  • 57
Nikhil Bharadwaj
  • 867
  • 4
  • 24
  • 42

1 Answers1

0

You can use:

Update table set c2=(Select C2 from table where c4=A1) where c1=value1

and so on by changing column values in inner query or using cursor.

Based upon this:

Bulk Record Update with SQL

you can do as:

update      Table
set         C2= c2
from        Table t1
inner join  Table t2
on          t1.c1 = t2.c1
Community
  • 1
  • 1
Muhammad Muazzam
  • 2,810
  • 6
  • 33
  • 62