How to Select the Sub category items the main category

Hi,

We have to display the sub-category dropdown.

We have to first select the first category and after that, those child elements are in the Second category.

But we have to store the first selection value to run the MySQL for 2nd dropdown like 2nd. \we are feeding mysql entries in dropdowm.