简体   繁体   中英

Update table inner join

I have two tables and i need to update one of them with respect to the id's of the second table

first table successlog ;

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

second table employeelist ;

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

I need to update the first table's shiftid with respect to the pid in the two tables.

I'm using the below query but its not working;

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

You statement must look like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM