Solved

sql query

Posted on 2003-11-28
4
869 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
Comment Utility
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
Comment Utility
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:dishanf
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now