Forum Moderators: open
SET @var_user = 'example';
REPLACE INTO tableA
SELECT username, colA, colB FROM tableB
WHERE username=@var_user
LIMIT 1; SET @var_user = 'example';
REPLACE INTO tableA
SELECT username, colA, colB FROM tableB
WHERE username=@var_user
AND tableB.updated > tableA.updated
LIMIT 1; SET @var_user = 'example';
REPLACE INTO tableA
SELECT tableB.username, tableB.colA, tableB.colB FROM tableB
LEFT JOIN tableA
ON tableB.username = tableA.username
WHERE username=@var_user
AND
(
tableB.updated > tableA.updated OR
COALESCE(tableA.updated, 0) = 0
)
LIMIT 1;