Where there are a number of valid answers, you are right that to change the question and invalidate them would not be a good thing to do.
Indeed, it's not a good thing when there are any answers, but at least when there is only one it's fairly easy to add a comment apologising and noting that the question has changed. Hopefully that will stave off any downvotes the answer might attract because it doesn't answer the question which later visitors see.
The best thing to do is to ask a new question in which you can link to your original. You may even be able to ask in such a way as to value the existing answers. "This was useful because it showed X. However, what I actually wanted to know was Y, and the answers don't cover that as I can't apply X because of Z," or something.
Actually, the best thing to do is to ask the right question in the first place. Take time to write it; make sure that there is no ambiguity at all. Do some research yourself, including looking for generalised keywords here which may be related to your query: and present your research in the question. You may find the answer to your query [in which case, upvote the post(s) as they've been useful] or you may be able to build on someone else's post and you can link to it for background.