How to define a query om a n-m table
- by user559889
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