Oracle SQL - 将值插入列和外键时出现问题

时间:2015-01-03 14:06:02

标签: sql oracle insert foreign-keys

我有一个表,其中包含来自2个单独表格和普通列的2个外键。我已设法将数据插入外键,但是我在将数据插入普通列时遇到问题。这是我的陈述

INSERT INTO Emp_LC
(EmpID, fName, sName, lCCode, Date)
SELECT * FROM
((SELECT EmpID FROM Employees WHERE jobDesc = 'Driver' OR Employees.jobDesc = 'DRIVER')), 
((SELECT lCCode FROM LicCerts WHERE Desc = 'Driving Licence'));

我想为此语句添加fName,sName和Date的值,但我无法确定将它们放在何处。我想在声明中的某个地方我需要'VALUES'。

提前致谢。

1 个答案:

答案 0 :(得分:1)

假设这些来自employees表,将它们添加到子查询和外部查询中:

INSERT INTO Emp_LC(EmpID, fName, sName, lCCode, Date)
    SELECT EmpId, fName, sName, lCCode, date
    FROM (SELECT EmpID, fName, sName
          FROM Employees
          WHERE jobDesc = 'Driver' OR Employees.JOBDESCRIPTION = 'DRIVER'
         ) CROSS JOIN 
         (SELECT lCCode, date
          FROM LicCerts
          WHERE Desc = 'Driving Licence'
         );

这假设date来自LicCerts