I don't know if the term update data with LEFT JOIN
is correct, because I'm actually using it for a condition WHERE
.
I have reviewed the following question: https://stackoverflow.com/questions/6335388/update-and-left-outer-join-statements
I have used one of the posted examples as follows, running directly on SQL:
UPDATE tbl_branch_office
SET id_enterprise=1,
business_name='prueba'
FROM tbl_branch_office b
LEFT JOIN tbl_access ac ON b.id_branch_office = ac.id_branch_office
WHERE b.id_branch_office=1 AND ac.id_user=2
But I get error:
There is an error in your SQL syntax; check the manual that corresponds to your MariaDB server version to find out the correct syntax to use near 'FROM tbl_branch_office b
This is my code with MYSQL with PHP:
$stmtIIE = $con->prepare("UPDATE tbl_branch_office
SET id_enterprise=?,
business_name=?,
ruc=?,
tradename=?,
establishment=?,
country=?,
city=?,
state=?,
address=?,
phone=?,
email=?,
active=?
FROM tbl_branch_office b
LEFT JOIN tbl_access ac ON b.id_branch_office = ac.id_branch_office
WHERE b.id_branch_office=?
AND ac.id_user=?");
What am I doing wrong?
The question you are inspired by is
SQL server
, I don't know if that syntax is correct there, I don't know much about itSQL Server
butMariaDB
it seems redundant to put aupdate
with afrom
try with
It is also important to avoid duplicate field errors between tables, that you put which table the fields are from, for example
SET b.id_enterprise=1, ...
orSET ac.id_enterprise=1, ..