1

I have two tables. One is EmployeeDatabase and other is EmployeeSalary.

Both has a column column employeeid...i want to fetch all the employeeid from EmployeeDatabase and fill it to the EmployeeSalary Table keeping in mind that no record get duplicated in salary table...i have made the employeeid column as unique in both table.

How to write query for this.

4

1 に答える 1

2
  • 使用INSERT INTO...SELECTステートメント
  • 関数LEFT JOINを使用して他のテーブルに存在しない ID をフィルタリングできるように、両方のテーブルを結合します。IS NULL

クエリ、

INSERT INTO EmployeeSalary (EmployeeID)
SELECT   a.EmployeeID
FROM     EmployeeDatabase a
         LEFT JOIN EmployeeSalary b
              ON a.EmployeeID = b.EmployeeID
WHERE    b.EmployeeID IS NULL
于 2012-11-19T05:34:55.483 に答える