transfer query to its appropriate table