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

next up previous contents index
Next: Self-Joins Up: Joining Tables Previous: One-to-Many Joins

Unjoined tables

When joining tables, it is necessary to join each table mentioned in the FROM clause by specifying joins in the WHERE clause. If you list a table name in the FROM clause, but fail to join it in the WHERE clause, the effect is to mark that table as unjoined, and cause it to be paired with every row in the query result. Figure [*] illustrates this effect.

  
Figure: Unjoined tables
\begin{figure}\begin{list}{}{
\setlength{\rightmargin}{\leftmargin}
\raggedrigh...
...~~2~\vert~~~~~3
\par ~~~~~3~\vert~~~~~3
\par (9~rows)\end{list}\par
\end{figure}

The first SELECT performs an ordinary join. The second SELECT does not join a column from wild_a to a column in wild_b, causing every value in wild_a to be matched with every value in wild_b. This effect is usually not intended and is called a Cartesian product. When a query returns many more rows than expected, look for an unjoined table in the query.


Bruce Momjian
1999-11-21