Basically I have a table "Products" with "Product_ID" and table "Sub_Categories" with "Sub_Category_ID".
Products that have a "Sub_Category" are linked using a bridge table, "SubC_Prod_Bridge", they are linked by ID "Products" and "Sub_Category_ID".
Like this:
Table: Products
Product_ID
4
Table: Sub_Categories
Sub_Category_ID
5
Table: SubC_Prod_Bridge
Product_ID Sub_Category_ID
4 5
I know this question is very basic. What I am really looking for is a good reference online for JOIN statements, any recommendations are really appreciated.
A JOIN clause is used to combine rows from two or more tables, based on a related column between them. Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers" table. The relationship between the two tables above is the "CustomerID" column.
INNER JOIN is ANSI syntax whereas the WHERE syntax is more relational model oriented. The INNER JOIN is generally considered more readable and it is a cartesian product of the tables, especially when you join lots of tables but the result of two tables JOIN'ed can be filtered on matching columns using the WHERE clause.
An inner join combines records from two tables based on a join predicate and requires that each record in the first table has a matching record in the second table. Thus, inner joins return only records from both joined tables that satisfy the join condition.
SELECT P.*, S.*
FROM Products P
JOIN SubC_Prod_Bridge B
ON P.Product_ID = B.Product_ID
JOIN Sub_Categories S
ON S.Sub_Category_ID = B.Sub_Category_ID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With