Skip to content
Advertisement

SQL query to remove duplicates from single column based on latest date

I have a table where I have duplicate values in just one column, and I want to remove those value using the column which has timestamp values. So the value which has latest timestamp should be in the expected result.

For example, using the below table column1 is varchar, column2 is timestamp

Looking at the above table I have two same values ABC but only the second one should be in the result because it has the latest timestamp value then the first, similar case with the JKL values.

Expected result

I have tried a few partitioning sql queries and also CTE but not able to get the desired result. Any help would be appreciated. Thanks

Advertisement

Answer

I have tried a few partitioning sql queries and also CTE but not able to get the desired result

Using QUALIFY it could be achieved without cte:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement