These УslyФ outer joins
Let it be necessary to define all ships with a known launch year (the training database УShipsФ) for each class. When Уfor each classФ is said, we already know that we must use outer join, for example, the left one:
That is, we join the Classes table with the Ships table by the СclassТ column and choose the ships with a known launch year. And this is what we get in result, apart from anything else:
But how can that be? WeТve used Сlaunched IS NOT NULLТ in the join predicate, havenТt we? And the answer to our question lies in the join predicate. LetТs get back to the definition of the left outer join:
All rows from the left table are combined with those from the right, for which the predicate value is true. If for any row from the left table there is not a single corresponding row from the right table then the values of the right table are NULLs.
In the Ships table there is no vessel of Bismarck class. ThatТs why we got this row, that is, the Bismarck class is in the Classes table. And what if such ship existed? LetТs add two ships of the Bismarck class into the Ships table Ц one with a known launch year, another with undefined:
Conclusion. If you need to restrict the resulting set of the outer join use WHERE clause, which serves exactly this purpose:
And the join predicate only defines which rows from different tables will be concatenated in the resulting set.
Finally, IТd note that this example is not quite revealing, as the INNER JOIN would fit into this solution as well, despite the Уfor each classФ words. But the flexibility of SQL(Structured Query Language) is a database computer language designed for the retrieval and management of data in relational database management systems (RDBMS), database schema creation and modification, and database object access control management.SQL language allows finding different variants, and stereotype usage is fully justified.