Update on related table (subselect)
Posted by:
Wojtek K
Date: October 10, 2005 03:37AM
Hello,
I'm not sure if this forum is accurate, but it's more or less related to Oracle SQL.
is there any way to conduct an update based on other table values, in MySQL 4?
exemple:
table t1:
id int(22), value1 decimal(15,4))
table t2:
id int(22), value2 decimal(15,4))
id is unique.
I'd like to make an update on column t1.value1, replcing them by t2.value2 for each t1.id=t2.id.
On Oracle is similar to :
------------------
BEGIN
DECLARE
i PLS_INTEGER;
BEGIN
FOR i IN (SELECT t2.id, MAX(value2) AS value2
FROM t2
GROUP BY t2.id)
LOOP
UPDATE t1
SET t1.value1 = i.value2
WHERE t1.id = i.id;
END LOOP;
COMMIT;
END;
END;
Trying to do this on MySQL I get an error. Is it possible to do such a thing?
I will be grateful for all sugestions
Thanks in advance.
Regards
Wojtek
Edited 1 time(s). Last edit at 10/10/2005 04:46AM by Wojtek K.
Subject
Views
Written By
Posted
Update on related table (subselect)
9599
October 10, 2005 03:37AM
3729
October 16, 2005 07:19AM
2666
November 09, 2005 11:12AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.