The question is obviously off-topic, as it is purely a SQL question, and has nothing to do with WordPress, other than the table being queried is a WordPress database table. The answer posted reiterates that the question is off-topic for WPSE, as it involves nothing more than SQL syntax. (The answer itself is probably low quality, as it's basically a link, with no explanation for how to implement the syntax in the context of the original question; but that's beside the point of this question.)
While I trust that the site mechanics will prevail with respect to the question itself, I am concerned that I often see answers posted to off-topic questions before the question receives enough close-votes (or moderator attention) to close the question. Providing answers to clearly off-topic questions is counter-productive to the purposes of WPSE, as it both dilutes the WordPress-specific questions and answers, and also encourages more people to ask off-topic questions.
So, what is the preferred way to handle? I can see at least three possible actions:
- Leave a comment on the answer, requesting that such answers to off-topic questions not be posted
- Downvote the answer
- Flag the answer
If option 1, it would probably be preferable to have some "boilerplate" text to use for such a comment, so as not to sound like a jerk when leaving the comment. If option 2, I wonder if downvoting and the loss of rep points would overly discourage someone who in all likelihood is merely trying to help, but doing so in a misguided/uninformed manner. If option 3, I wonder what the appropriate moderator action would be in response to the flag.