Solved

sql query

Posted on 2003-11-28
4
903 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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…

742 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