There is such a base structure: data schema

  1. Table EMPLOYEE - employees. The DOCUMENT column contains the series and number of the passport.
  2. Table OCCUPATION - posts.
  3. Table DIVISION - divisions.
  4. Table OCC_DIV - the relationship of the position and units.
  5. Table EMPL_OCC - link employees and positions.

The task is as follows:

  1. Select posts that belong to the Sales division. Display job titles.
  2. Select employees with the post "Driver". Print the full name of employees and dates of employment.

I suppose that it is necessary to use a JOIN , but how to use it in the second case, when there are two more between the necessary tables?
And in the second there is a connecting table, again it is not clear how to glue the tables?

  • And what is the difficulty, all the connections are the same? - Oleg GranRCM
  • one
    Consistently write join for all intermediate tables. - Mike

1 answer 1

JOIN is a join operator that takes three arguments: two tables and a predicate. The following form:

 <таблицаА> JOIN <таблицаБ> ON <предикатА_Б> 

... and it also returns a "table" (conditionally), so you can do this:

 (<таблица1> JOIN <таблица2> ON <предикат1>) JOIN <таблица3> ON <предикат12_3> 

... and if the brackets are removed, the result will be the same, so you can simply write a long chain of JOIN 's without brackets. It makes sense to accurately indent, so that you can clearly see which tables are linked and how:

 <таблица1> JOIN <таблица2> ON <предикат1> JOIN <таблица3> ON <предикат12_3> JOIN <таблица4> ON <предикат123_4> 

Types of connections (left, right, etc.) are not taken into account for brevity, but syntactically they differ only in that y before the JOIN keyword will be specifying keywords about the type of connection: a la LEFT JOIN .