Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 only condition in sql

Author  Topic 

r2k
Starting Member

1 Post

Posted - 2014-11-02 : 12:07:57
Can anyone tell me how do we take care of only condition in sql?
for ex
Find the sids of suppliers who supply only red parts

schema is

suppliers(sid,sname,address)
parts(pid,pname,color)
catalog(pid,sid,price)

I wrote this as my answer but it is giving name of the ids of all the suppliers who supply red part:

select distinct c.sid
from catalog c, parts p
where not exists (select * from parts p where p.pid = c.pid and p.color <> 'red')



gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-02 : 13:46:16
select distinct c.sid
from catalog c
join parts p
on p.pid = c.pid
where p.color = 'red'
Go to Top of Page
   

- Advertisement -