加入这些表的正确方法是什么?

What is the correct way to join these tables?

**itemwhse**

item (primary key)
whse (primary key)
...other fields...


**job**

job (primary key)
suffix (primary key)
item
whse
...other fields...

job table 存储有关生产项目的作业的信息。这些物品是在某个仓库生产的,但随后可以将它们运输到另一个设施进行存储。 itemwhse table 是保存库存数量和项目编号的内容。

我注意到无论哪种方式我都得到了正确的信息,但我想知道哪个是正确的:在 itemwhse 上进行内部联接或在 item 上进行内部联接只有.


示例数据:

**itemwhse**

item        whse        qty
ItemA       BART        1000
ItemA       BEN         1500


**job**

job         suffix      item       whse        qty
foo1        1           ItemA      BART        2500

示例查询:

select

   j.job
   , j.suffix
   , j.item
   , j.whse
   , i.item
   , i.whse

from

   job as j
   inner join itemwhse as i on j.item = i.item

如果 item+whse 是一个复合主键,那么你应该同时加入它们。

Itemwhse 是关联 table,它将 ItemWarehouse 相关联,具有多重性 M:N。

如果您仅通过 item 加入 JobItemwhse,您将在所有仓库中获得特定类型的物品,而不仅仅是在相关仓库中。