I have a database table with the following columns regularization_dt, modified_dt and account_id. For a particular whenever an account is updated an entry is added in to the table with new modified_dt for the regularization_dt and account_id.
I want an SQL query to remove duplicates of regularization. Only one entry for the regularization should be selected based on the recent modified_dt.
For example the entries in the table are as follows:
regularization_dt | account_id | modified_dt
----------------- | ---------- | ----------
03-28-2013 | 123 |05-26-2014
03-28-2013 | 123 |01-14-2014
05-26-2014 | 123 |05-25-2014
The resulting query should yield:
regularization_dt | account_id | modified_dt
----------------- | ---------- | ----------
03-28-2013 | 123 |05-26-2014
05-26-2014 | 123 |05-25-2014
How should I remove duplicates of a column based on a different column?
select * from history where account_id = 123;