Merge two database queries into one.