fix join query when defining as table.