Copy unique records from one table to another in SQL Server

In this post, I provide you one script to copy a unique record from one table to another.

You can perform this activity using ROW_NUMBER() and PARTITION BY clause.

This partition clause identified set of duplicate records and row_number assign an ID for this set.

Below is full demonstration:

Let’s first create table with some records:

Result of above select statement is:

copy unique record sql serverYou can see ABC and EFG are duplicate name.

Now let’s create a second table with copy unique data from the first table.

Now result of above second table is:

copy unique record sql serverNow you can see all names are unique and copied only seven unique records.

Anvesh Patel

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz