I am attempting to copy data from specific columns in one row, and have it inserted/updated into another row, all in the same table. Each row already has an ID # (called order_no), so no auto-increment is needed.
I thought this would be pretty simple, but it’s just not working. my Table name is ‘orders’ and the columns are called ‘rn’ and ‘phone’ and the order_no are ‘416’ and ‘417’. I want rn, and phone from 416 to be inserted into the rn, and phone columns for 417.
I also have tried this query, attempting to copy just one record rn, with no success
and get error: #1248 – Every derived table must have its own alias
mysql_query("UPDATE orders
SET rn =
( SELECT rn
FROM ( SELECT rn
FROM orders
WHERE order_no = 416
)
WHERE order_no = 417 ");
I have tried this with no success, and get Error #1136 – Column count doesn’t match value count at row 1
mysql_query
(" INSERT INTO orders (rn, phone)
SELECT rn, phone, 416
from orders
WHERE order_no = 417 ");
Update. I also tried this query below, with just one field (rn) to no avail, and it throws error #1093 – You can’t specify target table ‘orders’ for update in FROM clause:
mysql_query("UPDATE orders
SET rn = (SELECT rn FROM orders WHERE order_no = '416')
WHERE order_no = '417' ");
Any help or assistance is greatly appreciated. Thank you
You can modify your query
to