我在数据库中有三个表tbProduct,tbCompany,tbCompanyProduct
tbProduct
tbCompany
tbCompanyProduct
现在我必须执行连接操作以获取分配给公司的所有产品,即基于@companyid参数... 请帮帮我!!!
答案 0 :(得分:2)
您的查询将如下所示......这是三个表之间的简单连接...
SELECT comp.CompanyName, prod.ProductX
FROM tbCompanyProduct compPro
INNER JOIN tbCompany comp ON compPro.Company = comp.CompanyId
INNER JOIN tbProduct prod ON prod.Product = compPro.Product
WHERE comp.CompanyId = yourCompanyId