连接

当两个或多个表被同一列或多个列连接时发生连接,它创建新的结果表。下图显示了一个查询,该查询使用 itemsstock 表的子集来说明连接的概念。

图: 两个表之间的连接


This figure is described in the surrounding text.

下列查询将 customerstate 表连接起来。

图: 查询

SELECT UNIQUE city, state, zipcode, sname
      FROM customer, state
      WHERE customer.state = state.code; 
该结果包含 customerstate 表的指定行和列。

图: 查询结果

city            state zipcode sname
      
      Bartlesville    OK    74006   Oklahoma
      Blue Island     NY    60406   New York
      Brighton        MA    02135   Massachusetts
      Cherry Hill     NJ    08002   New Jersey
      Denver          CO    80219   Colorado
      Jacksonville    FL    32256   Florida
      Los Altos       CA    94022   California
      Menlo Park      CA    94025   California
      Mountain View   CA    94040   California
      Mountain View   CA    94063   California
      Oakland         CA    94609   California
      Palo Alto       CA    94303   California
      Palo Alto       CA    94304   California
      Phoenix         AZ    85008   Arizona
      Phoenix         AZ    85016   Arizona
      Princeton       NJ    08540   New Jersey
      Redwood City    CA    94026   California
      Redwood City    CA    94062   California
      Redwood City    CA    94063   California
      San Francisco   CA    94117   California
      Sunnyvale       CA    94085   California
      Sunnyvale       CA    94086   California
      Wilmington      DE    19898   Delaware