Reputation: 309
I am new to SQL. Are these SQL statements equal in terms of their output?
Suppliers
(sid: integer, sname: string, address: string)Parts
(pid: integer, pname: string, color: string)Catalog
(sid: integer, pid: integer, cost: real)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
Reputation: 56
They're not same. If Parts has multiple rows with one PID, it will return duplicate suppliers record.
Upvotes: 2