I have a problem! My shops table contains 4 rows, each containing a shop name, ID and other data relevant to that shop.
I also have a "bind" table where I select which product categories should be visible in which shops. Naturally the bind table will contain more rows... I would like to select all the shops from the shops table, and join only the rows in the right table, the bind table, if the shop ID is the same.
SELECT * , b.categoryId as bindCategory
FROM shops
LEFT JOIN bind_shop_category AS b
ON shops.shopId = b.shopId
If I do it like that, I get all the binds, with their corresponding shop data, not just the shops and their corresponding bind data. :P
This is very confusing, and I'm not sure I formulated the question 100%.
Uhm... expected data:
shopId shopName bind.categoryId
1 shop1
2 shop2 category1
3 shop3 category1
4 shop4