I am struggling to come up with the SQL query to find the all the products accessible to user under a particular division.
A division can have many products.
Division table has division_id and division_name.
Product table has product_id, product_name and division_id.
I have another table called UserProducts where I have columns like
user_id, division_id and product_id.
In the UI part while assigning products to user, division is selected first and then based on selected division products are populated.
In addition to the products from products table, the product drop down has one more option called as ALL.
When ALL option from product is selected all products under the division are assigned to the user.
But in the User products I do not enter entry for all the products. It has only one entry like
user_id = 1, division_id = 1 and product_id = -1
where -1 says its ALL products under division_id = 1
Also user can have access to many divisions. So User can have access to all products under division A but only two products under divison B.
Now, with this schema how do I get all the products accessible to user under division?
EDIT 1
I will have user id and product id as inputs and i would want to get all the products accessible to given user under given division.
Input : user_id, division_id
output : List of all products by user_id and division_id
Please help.
1 Answer