Danish
Danish

Reputation: 353

Combine Multiple Table on a value

I have three tables. The third table has foreign keys to the first two. Please see the attached screenshot for reference.

I want to select rows from Medicines based on category_ID and in result of this query I also want to show Comp_Name and category_Name of the resulted rows.

[enter image description here]

Upvotes: 0

Views: 44

Answers (1)

Pawel Czapski
Pawel Czapski

Reputation: 1864

Below is query for you, you need to use INNER JOIN

select Comp_Name, Category_Name
from Medicines as m
inner join Categories as c on c.Category_ID = m.Category_ID
inner join Company as co on co.Comp_ID = m.Comp_ID

just add your WHERE clause...

where m.Category_ID = 'your category id'

Upvotes: 1

Related Questions