UPDATE table1
SET table1.col1 = table2.col2
FROM table2 WHERE table1.id = (SELECT MAX(id) FROM table1) AND table2.ID = (SELECT MAX(ID) FROM table2);
ich einen Syntaxfehler, aber ich weiß nicht, wie es zu tun.
UPDATE table1
SET table1.col1 = table2.col2
FROM table2 WHERE table1.id = (SELECT MAX(id) FROM table1) AND table2.ID = (SELECT MAX(ID) FROM table2);
ich einen Syntaxfehler, aber ich weiß nicht, wie es zu tun.
Unter der Annahme, dass id
in Tabelle 1 eindeutig zuzuordnen ist:
UPDATE table1 t1
SET t1.col1 = (select t2.col2 from table2 t2 order by id desc limit 1)
ORDER BY t1.id DESC
LIMIT 1;
Dies aktualisiert die "letzten" row in table1
(durch id
) mit dem "letzten" row in table2
(durch id
).
Ihre Syntax funktioniert nicht auf vielfältige Weise:
FROM
Klausel in UPDATE
unterstützt.MySQL
update table1
cross join (
select col2
from table2
order by id desc
limit 1) as A
inner join (
select id
from table1
order by id desc
limit 1) as B on (B.id = table1.id)
set table1.col1 = A.col2
Sie verwenden nicht-MySQL-Syntax für die 'update' beizutreten. –