Answer the question
In order to leave comments, you need to log in
How to compose Update according to Select data by condition from another table?
There is a table 1 from which we get a selection:
SELECT a.region,a.host
FROM ftpup a
, ( SELECT info,type,timestamp, max(date) as time FROM ftpup GROUP BY type ) b
WHERE a.type = b.type AND a.date = b.time AND a.status <> '0' ORDER BY a.`date` DESC
Answer the question
In order to leave comments, you need to log in
Yes, I already blinded a little earlier. You have the same logic.
UPDATE table2
INNER JOIN (SELECT a.region,a.host
FROM ftpup a
, ( SELECT info,type,timestamp, max(date) as time FROM ftpup GROUP BY type ) b
WHERE a.type = b.type AND a.date = b.time AND a.status <> '0' ORDER BY a.`date` DESC) AS table1
ON (table2.hostname = table1.host AND table2.region = table1.region)
SET table2.status=2
I'm not sure, but try this (try on test data):
UPDATE my_tab2 as t2
JOIN (SELECT a.region,
a.host
FROM ftpup a,
(SELECT info,
type,
timestamp,
max(date) as time
FROM ftpup
GROUP BY type ) b
WHERE a.type = b.type
AND a.date = b.time
AND a.status <> '0' ) AS t1 ON t1.host = t2.host and t1.region = t2.host
SET t2.status = '2'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question