I have some SQL knowledge, but for this is just too much

I would need an SQL that would grab the country_flag column from smf_members table on tarantino_smf database with the content "us", "uk", "nl" and copy to phpbb column user_flag of table phpbb_users (created by this extension). The difficulty of this sql for me is that user_flag have an number that exists at table phpbb_flags that connects the number on phpbb_users.user_flag column with the id of phpbb_flags.user_flag. And phpbb_flags has a column name flag_image with "us.png", "uk.png", "nl.png".
Theorically I would need to compare if the username is the same (by comparing smf_members.member_name with phpbb_users.username) and if it is the same username then it would set the new flag. And for that it would need to check if the content of smf_members.country_flag (us) is on phpbb_flags.flag_image (us.png) and if it is, it would grab the phpbb_flags.flag_id and set it on phpbb_users.user_flag.
Could anyone help? Thanks!