Kauthon
Kauthon

Reputation: 181

MYSQL update clause comparing the WHERE from 2 tables

$produpd = "UPDATE tblnavpc SET tblnavpc.ChildName = tblnav.NavName " .
    "FROM tblnav WHERE tblnavpc.CID = tblnav.NavID";

This is the error I get"

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM tblnav WHERE tblnavpc.CID = tblnav.NavID' at line 1

I know keys aren't named greatly but I just trying to fix this one problem, I didn't name the tables.

Upvotes: 0

Views: 393

Answers (2)

iBiryukov
iBiryukov

Reputation: 1740

"From" cannot be used with update statements. Should be

$produpd = "UPDATE tblnavpc SET tblnavpc.ChildName = tblnav.NavName " .
    "WHERE tblnavpc.CID = tblnav.NavID";

Upvotes: 0

Greg
Greg

Reputation: 321766

You don't have a FROM clause in an update:

UPDATE tblnavpc
INNER JOIN tblnav ON tblnavpc.CID = tblnav.NavID
SET tblnavpc.ChildName = tblnav.NavName

Upvotes: 3

Related Questions