更新表内连接

时间:2014-08-29 06:39:59

标签: mysql sql-update inner-join

我有两个表,我需要根据第二个表的id更新其中一个表

第一个表成功日志;

Id     pid      shiftid
1       2          
2       2          
3       2          
4       5          
5       5
6       6
7       6   

第二个表 employeeselist ;

Id    pId      shiftid
1      2          1
2      5          1
3      6          2

我需要针对两个表格中的shiftid更新第一个表格的pid

我正在使用以下查询,但它不起作用;

        $sql1="UPDATE successlog
                SET successlog.shiftid = employeelist.shiftid
                 FROM successlog
                 INNER JOIN employeelist
                 ON successlog.pid=employeelist.pId";  

2 个答案:

答案 0 :(得分:1)

你的陈述必须如下:

$sql1="UPDATE successlog INNER JOIN employeelist  ON successlog.pid=employeelist.pId
            SET successlog.shiftid = employeelist.shiftid";  

答案 1 :(得分:1)

UPDATE successlog 
INNER JOIN employeelist
ON successlog.pid=employeelist.pId 
SET successlog.shiftid = employeelist.shiftid