How to define a query om a n-m table

Posted by user559889 on Stack Overflow See other posts from Stack Overflow or by user559889
Published on 2011-01-01T18:10:55Z Indexed on 2011/01/01 18:54 UTC
Read the original article Hit count: 306

Filed under:
|

Hi,

I have some troubles defining a query. I have a Product and a Category table. A product can belong to multiple categories and vice versa so there is also a Product-Category table.

Now I want to select all products that belong to a certain category. But if the user does not provide a category I want all products. I try to create a query using a join but this results in the product being selected multiple times if it belongs to multiple categories (in the case no specific category is queried).

What kind of query do I have to create?

Thanks

© Stack Overflow or respective owner

Related posts about sql

Related posts about query