Nida
Nida

Reputation: 1702

How to perform join operation when three tables are linked?

I have three tables in database tbProduct, tbCompany, tbCompanyProduct

tbProduct

tbCompany

tbCompanyProduct

Now I have to perform join operation for fetching all the products assigned to a company i.e on the basis of @companyid parameter... Please help me !!!

Upvotes: 0

Views: 48

Answers (1)

Dipen Adroja
Dipen Adroja

Reputation: 425

Your query will look like this.....It is simple join between three tables...

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

Upvotes: 2

Related Questions