I'm using
SELECT m.id, r.username AS `from`, s.username AS `to`, m.message
FROM msgs m
INNER JOIN usrs r ON r.user_id = m.from
INNER JOIN usrs s ON s.user_id = m.to;
to replace user ids with user names in the 'from' and 'to' columns of messages and then output it to a file with mysql usrmsgs < script.sql > output.txt
I'd like to replace the user ids in 'from' and 'to' in the msgs table itself with the corresponding user names from usrs. What's the best way to do this?