我有一個有大量行(> 10K)的表。大多數行具有與ques_id關聯的重複角色值。我是新來的SQL。 我想要做的是按不同的最新ques_id選擇行。 這是我的表(tbl_questions)結構。SQL從表中選擇不同的最後一個值
id | ques_id | question | ans
1 | 2 | HTML stands.. | 3
2 | 5 | PHP stands.. | 2
3 | 6 | CSS stands.. | 4
4 | 6 | CSS stands.. | 4
5 | 5 | PHP stands.. | 2
6 | 6 | CSS stands.. | 4
這將是理想的結果:
id | ques_id | question | ans
1 | 2 | HTML stands.. | 3
5 | 5 | PHP stands.. | 2
6 | 6 | CSS stands.. | 4
下面是到目前爲止,我已經試過查詢:
SELECT DISTINCT ques_id, question, ans FROM tbl_questions
這不是「只是另一個角度」。這實際上可能會超越我自己的解決方案! – Strawberry