UPDATE YourTable
SET old_customer_id = customer_id, customer_id = 5
MySQL copy query records to new table field and update current records
https://stackoverflow.com/questions/22161925
- |
Question
I'm query the result and I would like to copy customer_id
to new table field old_customer_id
and the customer_id
will replace the latest records.
+-------------+-----------------+
| customer_id | old_customer_id |
|-------------+-----------------+
| 5 | |
| 3 | |
| 1 | |
+-------------+-----------------+
After my query get the result like above, I would like to copy the customer_id
to old_customer_id
which it will
+-------------+-----------------+
| customer_id | old_customer_id |
|-------------+-----------------+
| 5 | 5 |
| 5 | 3 |
| 5 | 1 |
+-------------+-----------------+
No correct solution
OTHER TIPS
UPDATE table_name SET old_customer_id = customer_id, customer_id = @your_new_customer_id;
You can try two separate UPDATE
queries. First update the old_c_id
field then update the c_id
.
something like:
UPDATE customerTable
SET old_c_id = c_id;
Then, set the c_id
in another UPDATE
query.
Not sure what would happen if you tried both in the same query though, probably works:
UPDATE cTable
SET old_c_id = c_id, c_id = ??;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow