There are 2 tables they are connected, but it is necessary that when, when adding a new row, it would refer to the first table and, by the row id, pass a specific row to the second table.

something like this but in automatic format.

INSERT INTO trooms(`hotelsname`) SELECT hotelname FROM `thotels` WHERE id = 80 

Please help in this issue. Thanks in advance

  • Why do you need it? what id line is where it comes from. If you have one table referring to another by id and at the same time you need to tighten some value from the parent table into it, then you have the wrong base model, it breaks the second normal form. In general, "automatically" - this means triggers - Mike
  • The point is, I have a base with the name of the hotels thotels and there is a base of rooms trooms. And I need to do it so that when I add a room, I need to tie it to a specific hotel, so that when they open the page of that hotel, only its rooms would be displayed. - Pavel
  • And why do you need somewhere to insert the name of the hotel except in the very table of hotels? You keep the hotel id in the rooms and on this id show all the rooms related to the hotel you need - Mike

0