Skip to content
Advertisement

“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 hereI 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;

Advertisement

Answer

    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/

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement