Suppose I have a large table in the database with some number of columns, and Im interested in 4 of them: id, level1, level2, and level3.

While id is a unique identifier for each row, so is the combination of level1, level2 and level3.

I want to create three dropdowns:

The first one chooses from available level1 values.

Given the choice in the first dropdown, the second chooses from corresponding level2 values.

Given the choice in the first and second dropdown, the third chooses from corresponding level3 values, and saves the corresponding row id.

Currently I am performing a new but smaller query every time a choice is made in any of the three dropwdowns. Is this the more efficient way? Or is there a nicer option where I do one large query of everything at the start, and slowly filter out using the information I get from each dropdown? If the latter is more efficient, what would be the best way to implement this?