I have table pref having column value. This value has type text. I want copy the value field value of row with id 7 to the value field of row with id 1. Can you please help how to do this. I know MS SQL, but I am new to mySQL.
create table pref
(
id int,
value text
)
In MySQL you can't use a subselect from the same table you are updating, but you can use a join.
UPDATE pref AS target
LEFT JOIN pref AS source ON source.id = 7
SET target.value = source.value
WHERE target.id = 1;
UPDATE
pref
SET
value = (SELECT value WHERE id = 7)
WHERE
id = 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With