Good day. I mimic the attitude of many to many due to the add. tables. Pseudocode:

Здание --------- id serial имя text Расположение --------- id serial название text Здание-Расположение -------- id sedial здание integer references Здание (id) расположение integer references Расположение (id) 

The problem is that I am a noob in SQL. The question is as follows. How do I properly fill in and retrieve data? Now I do everything in a few requests. Is it possible to add or retrieve data for all tables at once? If yes, please provide a sample code.

    2 answers 2

    Data is added to only one table. Those. you need to first add the data to the Task and Location tables (in any order), and then to the Building-Location so that the foreign key constraint error does not occur.

       SELECT * FROM Здание INNER JOIN Здание-Расположение ON Здание-Расположение.здание = Здание.ID INNER JOIN Расположение ON Расположение.id = Здание-Расположение.Расположение 

      It depends on what you need to get. INNER JOIN can be changed to LEFT OUTER JOIN.