UPDATE friends INNER JOIN users ON friends.friendid=users.userid
SET friends.friendname=users.username