There are such ASC tables: id, summa, user, name, id_match; InfoUser: id, user_id, balans.

Table ASC values ​​are:

  • id = 1, summa = 100, user = 1, name = GG, id_match = 5;
  • id = 2, summa = 300, user = 2, name = GG, id_match = 5;
  • id = 3, summa = 200, user = 3, name = YY, id_match = 5;
  • id = 4, summa = 700, user = 4, name = ZZ, id_match = 6;
  • id = 5, summa = 430, user = 5, name = AA, id_match = 6;

InfoUser table:

  • id = 1, user_id = 1, balans = 0;
  • id = 2, user_id = 2, balans = 0;
  • id = 3, user_id = 3, balans = 0;
  • id = 4, user_id = 4, balans = 0;
  • id = 5, user_id = 5, balans = 0;

You need to select all users from the ASC table, i.e. user fields (user field (ASC table) == user_id field (InfoUser table)) and change their balans field (InfoUser table) to the value from the summa field (ASC table). How to make such a request?

  • And which side is bolted Match ? What does she even do in this matter? - Akina
  • aah .. for sure .. well, she doesn't need her here, sort of ... - Eugene

1 answer 1

Probably you will need to change the name of one of the tables :) ASC

 UPDATE InfoUser JOIN `ASC` ON `ASC`.user = InfoUser.user_id SET InfoUser.balans = `ASC`.summa; 
  • Only it should be strictly stipulated that in the ASC table the user field must be unique. Otherwise, this lottery will work. And the name of the table itself should be framed with bactika. To avoid ... - Akina