I've a query :
select C.ChapterID, C.ChapterName, TA.TestAllotmentID,
T.TestName, S.StudentFname, B.BatchName, TA.UpdatedDate
from TransTestAllotment TA,
MstStudent S,
MstBatchDetails B,
MstTest T,
MstChapter C
where TA.StudentID = 47
and TA.BatchID = 10
and T.TestID = TA.TestID
and S.StudentID = TA.StudentID
and B.BatchID = TA.BatchID
and T.ChapterID = C.ChapterID
and TA.IsAttempted = 'True'
and TA.IsEvaluated = 'True'
order by TA.UpdatedDate desc
It returns result as below.
+-----------+-----------------------+-----------------+-------------------------+
| ChapterID | ChapterName | TestAllotmentID | UpdatedDate |
+-----------+-----------------------+-----------------+-------------------------+
| 52 | HTML Basics - Part II | 37 | 2016-03-14 13:12:53.000 |
| 52 | HTML Basics - Part II | 36 | 2016-03-14 13:11:59.000 |
| 52 | HTML Basics - Part II | 35 | 2016-03-14 13:11:35.000 |
| 50 | HTML Basics - Part I | 28 | 2016-03-11 18:45:51.000 |
| 50 | HTML Basics - Part I | 27 | 2016-03-11 18:45:05.000 |
| 50 | HTML Basics - Part I | 26 | 2016-03-11 18:43:48.000 |
| 50 | HTML Basics - Part I | 24 | 2016-03-11 18:42:37.000 |
| 50 | HTML Basics - Part I | 22 | 2016-03-11 18:41:07.000 |
+-----------+-----------------------+-----------------+-------------------------+
Now I want to retrieve distinct record based on chapter ID order by Updated date. The final output that I am expecting is:
+-----------+-----------------------+-----------------+-------------------------+
| ChapterID | ChapterName | TestAllotmentID | UpdatedDate |
+-----------+-----------------------+-----------------+-------------------------+
| 52 | HTML Basics - Part II | 37 | 2016-03-14 13:12:53.000 |
| 50 | HTML Basics - Part I | 28 | 2016-03-11 18:45:51.000 |
+-----------+-----------------------+-----------------+-------------------------+
How do I write a SQL query to get this output?