1

The below query is working fine but not updating records in the database. In my database there is three records available for update, but it's not updating.

UPDATE vgm_details VD SET VD.job_id = ( select S.job_id from stuffings S JOIN vgm V ON S.booking_id = V.booking_id WHERE S.container_no = VD.container_no) where VD.job_id = 0;

i have attached screenshot of vgm_details table.

enter image description here

1 Answer 1

1

Instead of subquery (and related issue for scoping) You could use an update with join

UPDATE vgm_details VD 
INNER JOIN  stuffings  S ON S.container_no = VD.container_no
INNER JOIN vgm V  ON S.booking_id = V.booking_id 
SET VD.job_id = S.job_id 
WHERE VD.job_id = 0;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.