how to (even logically) random at least one e.g. Id from database which has specified column value?
I mean I have in database table id, question id, answer text value and bool (if answer is correct) columns and I want to get e.g. three answers Ids, that (at least) one of them is correct.
Many thanks for your help in advice!
So you want to make a multiple choice thing, and display x out of y answers where, out of those y, c are correct, and w are wrong (c+w=y).
I would suggest using 2 queries, first get a random correct answer, and then get x-1 incorrect answers. I would recommend against using two or more correct answers, as it will just confuse the user.
To get the correct answer, you could do:
After that do
If you do want to include any other answer, including a correct one, you could do
Since the questions won’t have a large answer set (I guess not more that 10 or 20), using NEWID() on each row will not be very bad for performance.