Fixed query bug in orderTables