我想在表中插入从另一个表中获取的值。我正在使用IBExpert。像这样:
INSERT INTO employeemove (cdemployeemove,cdclient,datestart,cdclientwhere,cdcateg)
SELECT gen_id(EMPLOYEEMOVE_NEXTCODE, 1),
SELECT em.name_code from employee_migration em where em.cdclient = 1,
SELECT em.fired_date from employee_migration em where em.cdclient = 1,
cdclientwhere, -- from employeemove
cdcateg -- from employeemove
有没有办法做到这一点?
答案 0 :(得分:4)
大概您想要INSERT . . . SELECT
:
INSERT INTO employeemove (cdemployeemove, cdclient, datestart, cdclientwhere, cdcateg)
SELECT gen_id(EMPLOYEEMOVE_NEXTCODE, 1), em.name_code, em.fired_date,
cdlientwhere, cdcateg
FROM employee_migration em
WHERE em.cdclient = 1;
编辑:
我猜你想要这样的东西:
INSERT INTO employeemove (cdemployeemove, cdclient, datestart, cdclientwhere, cdcateg)
SELECT gen_id(EMPLOYEEMOVE_NEXTCODE, 1), em.name_code, em.fired_date,
emo.cdlientwhere, emo.cdcateg
FROM employee_migration em LEFT JOIN
employeemove emo
ON emo.cdclient = em.cdclient
WHERE em.cdclient = 1;