Update theme table using callback function in Ajax
You can access the values of the form elements using the $form_state parameter. So when you have the value of the select element, you can perform the query as required, build the table using theme_table and return the result. The returned result can be replaced or appended to the ajax wrapper defined in your form.