“SQL inner joins the right way”

rails, Uncategorized

The right way
select s.CompanyName
from Suppliers as s
where exists
select * from products p
inner join categories c on p.CategoryID = c.CategoryID
where c.CategoryName = “Seafood”
and p.SupplierID=s.SupplierID

The wrong way
SELECT DISTINCT Suppliers.CompanyName
FROM Suppliers INNER JOIN (Categories INNER JOIN Products ON
Categories.CategoryID = Products.CategoryID) ON Suppliers.SupplierID =
WHERE (((Categories.CategoryName)=”Seafood”))


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s