简体   繁体   中英

“From is not valid at this position” this is the syntax error I am getting while using Update join in mysql-Workbench

enter image description here I want to update the Paid column in Product when payment amount get inserted with respect to the product...

create table Product(
PID INT primary key,
Paid int not null default 0 ,
Total int not null
);



create table payment(
paymentid int primary key,
productid int not null,
amount int not null,
foreign key (productid) references product(paid)
);

(I am just using the dummy table to practice update using join)


update product 
set product.paid=(pay.amount+pr.Paid)
from-----> here I am getting error
payment pay 
inner join product  pr on
pay.productid=pr.pid;
    create table product(
PID INT primary key,
Paid int not null default 0 ,
Total int not null
);



create table payment(
paymentid int primary key,
productid int not null,
amount int not null,
foreign key (productid) references product(paid)
);

UPDATE
        product
    INNER JOIN payment ON product.PID = payment.productid
    SET
        product.Paid = (product.Total+payment.amount)
    WHERE
        product.PID = payment.productid

I test It now works fine. I hope It will work fine for you. Please let me know. If you still face same issue.Thanks. For more details. https://www.mysqltutorial.org/mysql-update-join/

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