Email: Password:       Forgot Password 
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.

Insert distinct Column value from one Table to Another Table without duplicate

Viewed:  1836 
Posted On:  08/07/2015 19:28:09 
SQL Server: Insert Column value from one table to another table. 


In this article I am going to explain how we can insert distinct Column value from one SQL Server table to another SQL Server table with avoiding delicacy.

Below is my First Table from which I will read distinct Manager Column value. Like  below:

Now see all records in my Employee Table:


Image 1.

Now select Distinct Manager Name from this Table


Image 2.

Below is my Second Table in which I will insert Manager Name:


Image 3.

Now write your SQL statement to achieve our desired functionality:


INSERT INTO Manager(ManagerName) 
   SELECT DISTINCT ManagerName  
    FROM Employee  
    WHERE ManagerName NOT IN(SELECT ManagerName FROM Manager);  



Image 4.

Now Select Records from manager table:


Image 5.

If you hit this Query again then it will not insert any duplicate record in Manager records and if a new Manager name comes in Employee table then it will insert that newly added manager name:


Image  6.

         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us