mysql> UPDATE `tb1` t
JOIN(
SELECT
name,
DATEDIFF(CURRENT_DATE(), `maxdata`) `dateDiff`
FROM
(
SELECT
name,
MAX(`myDates`)`maxdata`
FROM
tb2
GROUP BY
name
ORDER BY
`maxdata` ASC
)q
)x
SET t.GG = q.`dateDiff`
WHERE
t.name = q.name;
1054 - Unknown column 'q.name' in 'where clause'
mysql> UPDATE `tb1` AS t
JOIN(
SELECT
name,
DATEDIFF(CURRENT_DATE(), `maxdata`) `dateDiff`
FROM
(
SELECT
name,
MAX(`myDates`)`maxdata`
FROM
tb2
GROUP BY
name
ORDER BY
`maxdata` ASC
) AS q
)x
SET t.GG = q.`dateDiff`
WHERE
t.name = q.name;
mysql> UPDATE `tb1` t
JOIN(
SELECT
name,
DATEDIFF(CURRENT_DATE(), `maxdata`) `dateDiff`
FROM
(
SELECT
name,
MAX(`myDates`)`maxdata`
FROM
`tb2`
GROUP BY
name
ORDER BY
`maxdata` ASC
)q
)x
SET t.GG = x.`dateDiff`
WHERE
1
AND t.name = x.name;
Query OK, 100 rows affected
Rows matched: 162 Changed: 0 Warnings: 0
UPDATE tb1 AS t
INNER
JOIN ( SELECT name
, DATEDIFF(CURRENT_DATE,MAX(mydates)) AS `dateDiff`
FROM tb2
GROUP
BY name ) AS x
ON x.name = t.name
SET t.GG = x.`dateDiff`
note to both – if you’re gonna use JOIN, then you gotta use ON