I guess you have a Many-to-Many
relationship in which States
can have multiple Products
and Products
can be on different States
. So you need to join States
into the mapping table StateProducts
so you can be able to get the products on table Products
.
SELECT a.State_ID,
a.State_Name,
a.State_AbbreviatedName,
b.Product_Id,
b.Product_Name,
c.StateProduct_Price
FROM States a
INNER JOIN StateProducts c
ON a.State_ID = c.State_Id
INNER JOIN Products b
ON b.Product_Id = c.Product_Id
To further gain more knowledge about joins, kindly visit the link below:
UPDATE 1
use CROSS JOIN
keyword,
SELECT a.state_id, a.state_name, a.state_abbreviatedname, b.product_id, b.product_name, c.stateproduct_price
FROM states a
CROSS JOIN products b
LEFT OUTER JOIN stateproducts c
ON a.state_id = c.state_id AND
b.product_id = c.product_id