Solved

sql query

Posted on 2003-11-28
4
896 Views
Last Modified: 2012-08-14
I have three table
supplier(sid,sname)
part(pid,pname,color)
catalogue(sid,pid,cost)

I want to find the sname of suppliers who supply EVERY RED part
My query is as the follow :it doesnt return any row for me.What is wrong???

SELECT s.sname, p.pid
FROM supplier AS s, part AS p, catalogue AS c
WHERE (((p.pid)=c.pid) And ((s.sid)=c.sid))
            and
  PID IN (SELECT PID FROM PARTS WHERE COLOR=""RED")

I think this only returns suppliers naem who supply any red parts.
 
0
Comment
Question by:ta2000
  • 2
4 Comments
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 70 total points
ID: 9839289
Select * from Supplier as RS
Where rs.sid not in  
(Select s.Sid
    from Supplier as S,
   (select pid
      from part
     where color = 'RED') as P
   Where Not exists (select c.sid from catalogue C
                              where s.sid = c.sid and P.Pid = c.pid)
   )

0
 
LVL 18

Expert Comment

by:nigelrivett
ID: 9840724
select s.sid, s.sname
FROM supplier s
join catalogue c
on s.sid = c.sid
join part p
on p.pid = c.pid
where p.color = 'Red'
group by s.sid, s.sname
having count(distinct p.pid) = (select count(distinct pid) from parts where color = 'Red')
0
 
LVL 8

Expert Comment

by:Dishan Fernando
ID: 9841784
supplier(sid,sname)
part(pid,pname,color)
catalogue(sid,pid,cost)

SELECT S.sname
FROM supplier S INNER JOIN catalogue C
ON S.sid = C.sid INNER JOIN Part P
ON C.pid = P.pid AND P.color = 'RED'
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 9841857
ok have i misread this?

1) do you want just ther suppliers
who supply the full range of parts for which the colour is red?


2) or the names of suppliers who supply RED parts ?


my query and nigel's attempt to do 1
 (nigels would work only if catalogue has a priamary key of sid,pid )
dishanf does 2

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question