在MySQL中INSERT..SELECT

时间:2010-08-06 04:53:57

标签: mysql insert

INSERT INTO tblprofile (fldDate,fldemployeeno,fldLName,fldFName,fldMI,fldEmployeeName,
                        fldShiftCode,fldProjectGroup,fldTask,fldSuperior,fldPosition)
SELECT now(),tblprofile.fldemployeeno,tblprofile.fldlname,tblprofile.fldfname,tblprofile.fldmi,tblprofile.fldemployeename,
       tblprofile.fldshiftcode,tblprofile.fldprojectgroup,tblprofile.fldtask,tblprofile.fldsuperior,tblprofile.fldposition
  FROM tblprofile
 WHERE tblprofile.flddate = (SELECT MAX(flddate) FROM tblprofile p
                              WHERE p.fldemployeeno IN ('EMP0001','EMP0002','EMP0003','EMP0004','EMP0005'))
   AND tblprofile.fldemployeeno IN
       ('EMP0001','EMP0002','EMP0003','EMP0004','EMP0005');

我想复制列表中所有员工的所有当前个人资料('EMP0001','EMP0002','EMP0003','EMP0004','EMP0005'),似乎在我的查询中它只插入一个(1 )行..

简而言之,我想尝试在一次执行中从tblprofile复制员工的所有当前配置文件?任何人都可以帮助我这样做..

1 个答案:

答案 0 :(得分:1)

从您的评论中可以看出,用户可能拥有多个个人资料,并且您想要最新的个人资料并为新个人资料设置当前日期。

将WHERE子句更改为此

FROM tblprofile t1  WHERE_flddate =(SELECT MAX(flddate)FROM tblprofile p WHERE p.fldemployeeno = t1.fldemployeeno)AND t1.fldemployeeno IN        ( 'EMP0001', 'EMP0002', 'EMP0003', 'EMP0004', 'EMP0005');