There are two tables: games (id, name, devices) and groped_games (id, game_id, group_name) . games.devices can store desktop or mobile . How games are stored in games:

 1 loto desktop 2 loto mobile 3 soccer desktop 4 soccer mobile 

You need to replace groped_games.dame_id , where the corresponding games.devices = 'mobile' the id game with the same name, but where games.devices = 'desktop' . I started writing a query, but something came to a standstill:

 UPDATE grouped_games SET games_id = (SELECT games_id FROM games WHERE #тут тупик) 

    2 answers 2

    Putting the question so-so. If I understood correctly

     update gg set game_id = g.id from groped_games gg join games g on g.id=gg.id 

      In my opinion, it will turn out something like

       update games t1, games t2, groped_games t3 set t3.game_id := t1.id where t1.name = t2.name and t1.devices = 'desktop' and t2.devices = 'mobile' and t2.id = t3.game_id