I have a query that deletes duplicate row form SQL table. The query looks like this:
with CTE as (
select *, row_number() over (partition by Time_stamp order by Time_stamp) rn
delete from CTe where rn > 1;
Query works fine. I just need to expand it's function however. I need to be able to scroll thru all tables in the database and find duplicate rows (leaving just one behind). So I am thinking to use a cursor.
Each table has a id colum called "Date_Stamp". Duplicate Rows are those that have matching id (keys), regardless of the reset of data in other columns.
How do I achieve that?