Search code examples
phpmysqlsqlinsert-updatemultiple-tables

I'm trying to update a table and call another row from different table


This query is supposed to only update points in csp table once the status is 3. the status is from a different table. I come up with an error. what did I do wrong with the coding here?

$sql_update_csp= "UPDATE csp SET ttlpoints = (ttlpoint+$point)" ;

$sql_update_earn =$sql_update_csp."WHERE xid='$xid' AND status='3'" ;

Solution

  • UPDATE c SET c.ttlpoints = (c.ttlpoint+$point)
    from csp c
    left join earn_act ea
    on c.column_name = ea.column_name
    WHERE c.xid='$xid' AND ea.status='3'
    

    where column_name will the be the column used for joining the 2 tables, like primary key and foreign key.

    Hope this helps.