Your question, your audience. Choose who sees your identity—and your question—with question security.
SELECT Products.ProductID, Products.ProductName, Products.SupplierID, Products.CategoryID, Products.QuantityPerUnit, Products.UnitPrice, Products.UnitsInStock, Products.UnitsOnOrder, Products.ReorderLevel, Categories.CategoryName, Suppliers.CompanyName FROM Products INNER JOINCategories ON Products.CategoryID = Categories.CategoryID INNER JOIN Suppliers ONProducts.SupplierID = Suppliers.SupplierID
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
So in the above example the first INNER JOIN is only pulling records where the CategoryIDs match between the Products and Categories tables. The second INNER JOIN is filtering the results further by including only the results where the SupplierIDs match between the Products an Suppliers tables.
No - you don't have to include the joining columns in the select statement when doing a join.
If the relationship were switched to a "one to many" (i.e. one product can have one or more categories and one or more suppliers) then the database structure would be a little different. There are a few ways to implement this, but one way would be to add a ProductID column on the Categories and Suppliers tables. Your statement would then look something like this...
SELECT *
FROM Products
INNER JOIN Categories
ON Categories.ProductID = Products.ProductID
INNER JOIN Suppliers
ON Suppliers.ProductID = Product.ProductID
You won't be able to have duplicate products because of the ProductID primary key constraint; however, there may appear to be duplicates in your result set because you are joining data from multiple tables.