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

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

Article:
Viewed:  719 
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:

1.png

Image 1.

Now select Distinct Manager Name from this Table

2.png

Image 2.

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

3.png

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);  

 

4.png

Image 4.

Now Select Records from manager table:

5.png

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:

6.png

Image  6.

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