如何从数据库中显示随机10条记录?

时间:2013-11-02 16:57:27

标签: c# sql database random-sample

如何从数据库中随机显示10个问题?如何检查数据库的答案是否正确?

        db.command(true, "SELECT * FROM question WHERE Age_group='" +category + "'");
        foreach (DataRow item in db.result.Rows)
        {
            question_list.Add (Convert.ToInt32(item["id"]));
        }

        for (int i = 0; i < max_question; i++)
        {
            int index = ran.Next(question_list.Count);
            question_choose.Add(question_list[index]);
            question_list.Remove(question_list[index]);
        }

1 个答案:

答案 0 :(得分:1)

select top 10 * from table order by newid()

另见"order by newid()" - how does it work?