Insert Distinct Column Value From One Table to Another Table in SQL

Here is my first table from which I will read the Distinct Manager column value. It is shown below.

Now see all the records in my Employee Table.


Figure 1: Employee Table

Now select Distinct Manager from this table as in the following:


Figure 2: Select a name

Here is my second table in which I will insert the Manager name:


Figure 3: Insert a name

Now write your SQL statement to achieve our desired functionality:

  1. INSERT INTO Manager(ManagerName)   
  2. SELECT DISTINCT ManagerName   
  3. FROM Employee   
  4. WHERE ManagerName NOT IN(SELECT ManagerName FROM Manager);   

Figure 4:
Execute Query

Now select records from the manager table:


Figure 5: Select Record

If you hit this Query again then it will not insert any duplicate records into the Manager records and if a new manager name is to be inserted into the Employee table then it will insert that newly added manager name:


Figure 6: Hit the Query