Sam
Sam

Reputation: 309

Are these SQL statements equal in terms of the output?

I am new to SQL. Are these SQL statements equal in terms of their output?

SQL query #1

SELECT S.sid
FROM Suppliers S
WHERE S.address = '221 Packer street'
   OR S.sid IN (SELECT C.sid
                FROM Parts P, Catalog C
                WHERE P.color = 'red' AND P.pid = C.pid)

SQL query #2

SELECT S.sid
FROM Suppliers S, Parts P, Catalog C
WHERE (P.pid = C.Pid AND P.color = 'red') 
   OR (S.address = '221 Packer street')

Upvotes: 1

Views: 42

Answers (1)

sokjukim
sokjukim

Reputation: 56

They're not same. If Parts has multiple rows with one PID, it will return duplicate suppliers record.

Upvotes: 2

Related Questions