Select at least one from each category?

后端 未结 3 1131
闹比i
闹比i 2021-02-09 07:29

SQLFiddle Link

I\'ve got an SQLite database with a bunch of test/exam questions. Each question belongs to one question category.

3条回答
  •  逝去的感伤
    2021-02-09 07:48

    Basically what you are looking for is select top N max values. I spend 3-4 hours in the morning for searching it. ( still i haven't success in it, you may need to wait few more hours ).

    For the temporary solution you can use group by option as follows,

    String strQuery = "SELECT * FROM so_questions group by category_id;";

    the output is as follows,

    enter image description here

    will be back with exact your requirement.

提交回复
热议问题