reduce query