Sorry about images, but I don't know how to make a similar example.
I have db on postgresql with tables:

Foreign keys for interest: engine_labeledimage.job_id <-> engine_job.id and engine_labeledimageattributeval.image_id <-> engine_labeledimage.id
So I want delete any row in engine_labeledimage and engine_labeledimageattributeval that connect to specific id in engine_job. Here sample my code:
delete from engine_labeledimageattributeval
using engine_labeledimage
where engine_labeledimage.job_id in (3981,3983,3984);
delete from engine_labeledimage
using engine_job
where engine_job.id in ( 3981,3983,3984);
Its work, but code delete any rows in tables (((((
What I do wrong (except back-up data and delete policies) ?
CodePudding user response:
Add the reference condition in first query:
delete from engine_labeledimageattributeval
using engine_labeledimage
where engine_labeledimageattributeval.image_id = engine_labeledimage.id
and engine_labeledimage.job_id in (3981,3983,3984);
