SQL: Joining table multiple times

Associate
Joined
6 Jan 2006
Posts
1,024
Location
Midlands
I need some sql help!

I have a product table and a category table. Each product can be in 1 or 2 categories.

CATEGORY TABLE
PKCatID Name
1, Cat 1
2, Cat 2
3, Cat 3

PRODUCT TABLE
ProductID FKCatID1 FKCatID2 Product Name
1, 2, NULL, Product 1
2, 2, 1, Product 2
3, 1, 3, Product 3

I need an sql query to return me all the products in different categories. i.e. return me 5 rows.

Product 1, Cat 1
Product 2, Cat 2
Product 2, Cat 1
Product 3, Cat 1
Product 3, Cat 3

How do i achieve this in sql?
 
Thanks for the replies.

I understand it is a poor db design. I had to bolt this 2nd category in.
 
Back
Top Bottom