In my application there are products and a product-variant-group which has a defined set of properties which a product of this group must declare and the combination of the properties is unique across that product-variant-group.
Example screen from amazon:

In the image the first select menu has all values obviously. The next select menu depends on the previously selected value, and so on.
Those defined group properties have a unique priority assigned to it which in the following derived table equals the property itself.
For a given property/priority and given list of of property/priority-value pairs. I want to retrieve its possible values.
The priorities of the value pairs must be smaller then the given priority.
public String[] getProductVariantGroupValues(int productVariantGroupId, int priority, Map<Integer, String> prevValues);
An example makes it much clearer:
I have an sql statement which lists all product-variant-group properties that related products have defined:
+---------+----------+-------- + | product | priority | value | +---------+----------+---------+ | 1 | 1 | Black | | 1 | 2 | 38 | | 1 | 3 | Dots | | 2 | 1 | Black | | 2 | 2 | 38 | | 2 | 3 | Stripes | | 3 | 1 | Yellow | | 3 | 2 | 40 | | 3 | 3 | Stripes | +---------+----------+---------+ Other view for understanding *(priority is arbitrary just for understanding, with this view this would be trivial)*: +---------+--------+--------+---------+ | product | value1 | value2 | value3 | +---------+--------+--------+---------+ | 1 | Black | 38 | Dots | | 2 | Black | 38 | Stripes | | 3 | Yellow | 40 | Stripes | +---------+---------------------------+
Call the above method with priority = 3 and prevValues = {(1, Black), (2, 38)} should result in following result array: {Dots, Stripes}.
If black is selected for property/priority 1 and 38 is selected for property/priority 2 the only possible following values for property/priority 3 are {Dots, Stripes}
The example is simplified and an arbitrary number of properties/priority should be supported. The query must be created dynamically to support arbitrary number of lower priority values.
Maybe I should just use the second table appraoch with a fixed set of properties which would make the unique constraint and this query very simple.
If I understand the question correctly, you have a value for priority 1 and for priority 2 and want to get all priority 3 values that match. The following query gets the products:
To get the priority 3 values requires or a clever select statement (assuming priorities are not repeated for a product):
These queries are to give you an idea of how to construct the queries in your code. The generalization should be pretty straightforward.