how to get suppliers name from 3 joined tables [closed]

I have three tables The first table of suppliers The second table of parts The third table is the suppliers of parts

I want to find the names of the suppliers whose city is the same as the city of the red piece. please help.

Picture

Answer

You can use inner join like below:

select sname from S inner join sp on s.s#=sp.s#
inner join p on sp.p#=p.p# and s.city=p.city

To get all the suppliers whose city is same as product ‘red’.

  select sname from S inner join sp on s.s#=sp.s#
    inner join p on sp.p#=p.p# and s.city=p.city and p.pname='red'

Leave a Reply

Your email address will not be published. Required fields are marked *