Why is my query returning an unexpected result? Here are the tables I am using:


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


I need to find the name of suppliers that supply two different parts with the same price. I keep getting the incorrect answer.

SELECT S.sname
FROM Supplers S
WHERE S.sid IN (SELECT C.pid
FROM Catalog C, Catalog C1, Parts P, Parts P1
WHERE C1.sid = C.sid  AND P.pid = P1.pid AND C1.cost = C.cost);
My best guess is that what you are actually trying to query is:

SELECT S.sname
FROM Suppliers S
WHERE S.sid IN (SELECT C.sid
FROM Catalog C, Catalog C1
WHERE C1.pid &lt;&gt; C.pid  AND C1.cost = C.cost);


I changed the subselect to return C.sid, and removed the parts table altogether, since in your original body text you stated no conditions on the table.

Is this what you are looking for?