UPDATE tabla1 SET username = (SELECT userid FROM tabla1, tabla2 WHERE tabla2.username = tabla1.username)