Полезная информация

next up previous contents index
Next: Unjoined tables Up: Joining Tables Previous: Choosing a Join Key

One-to-Many Joins

Up to this point, when two tables were joined, one row in the first table matched exactly one row in the second table. making the joins one-to-one joins. Imagine if there was more than one salesorder row for a customer id. Multiple order numbers would be printed. That would be a one-to-many join, where one customer row joins to more than one salesorder row. Suppose there were no orders made by a customer. Even though there was a valid customer row, if there was no salesorder row for that customer id number, no rows would be returned. We could call that a one-to-none join.8.5

Figure [*] shows an example.

  
Figure: One-to-many join
\begin{figure}\begin{list}{}{
\setlength{\rightmargin}{\leftmargin}
\raggedrigh...
...~~1~\vert~~~~~1
\par ~~~~~1~\vert~~~~~1
\par (3~rows)\end{list}\par
\end{figure}

Because row 1 in carton_a matches three values in table carton_b, the carton_a value is duplicated three times in the output. This is a one-to-many join. There is no matching 2 value in carton_b, so the 2 value does not appear in the output. This is an example of a one-to-none join.


next up previous contents index
Next: Unjoined tables Up: Joining Tables Previous: Choosing a Join Key
Bruce Momjian
1999-11-21