I have the table ABC with the following data
Id Name Date Execution id -- ---- --------- ------------- 1 AA 09SEP2019 11 1 AA 08SEP2019 22 1 AA 07SEP2019 33 2 BB 09SEP2019 44 2 BB 08SEP2019 55 2 BB 07SEP2019 66 And I want to get for every distinct ID in the table its max date. So the result set must be as the following
Id Name Date Execution id -- ---- --------- ------------- 1 AA 09SEP2019 11 2 BB 09SEP2019 44 The query that returns the result I need
WITH MaxDate as ( SELECT Id,Name,Max(Date) from ABC group by Id,Name ) SELECT view1.*, view2.exection_id from MaxDate view1, ABC view2 WHERE view1.date=view2.date and view1.name=view2.name; I don't like to get the max date for the distinct ID by this way. May be there is another way ? Might be there is more easiest way?