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.

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from