产品
id_产品 产品名称 组件ID
组件
组件 ID 组件名称
我这里有一个将在 Combobox 中的产品列表,右侧它将是 jtable,当我选择一个产品时,它会列出我需要的所有组件。如何在 selectProduct 中进行 sql 查询? 另请注意,1 个产品最多可以有 100 个组件。并且至少有 50 个产品
谢谢
最佳答案
并且您应该避免直接使用产品表中的 componetId 避免无用的产品复制以维护与组件的关系
为此 您可以创建一个特定的表来维护产品和组件之间的关系,例如:
table product_component ( id, product_id, componentdID )
然后您可以选择产品的组件为
select a.productName, b.nameofComponent
from product_component c
inner join product a on a.product_id = c.product_id
inner join component b on b.componentdID = c.componentdID
对于特定产品
select a.productName, b.nameofComponent
from product_component c
inner join product a on a.product_id = c.product_id
inner join component b on b.componentdID = c.componentdID
where a.product_id = your_product_id_value
关于java - Sql多对多查询问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51740135/