display 2 tables with checkboxes by ajax button
You should not put the table-building code in the ajax callback. Put the code to build the tables into the hook_form_alter() implementation that you are using to add the button. You can use $form_state['triggering_element'] to tell if the button has been pressed, and only execute the query and build the tables if you need to.