-
Hi, Is is possible to delete based on joining X tables with criteria from both? Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
simolus3
Dec 12, 2023
Replies: 2 comments
-
It's not possible to have joins on delete statements, but in most cases it's possible to come up with a subquery to use in final deleteStmt = delete(t1);
deleteStmt.where((t1) {
final subquery = db.select(t2)
..where((t2) => t2.foo.equalsExp(t1.bar) & t2.another.equals(3));
return existsQuery(subquery);
});
await deleteStmt.go(); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Foxsterc
-
That's perfect! I hadn't thought of using a subquery in drift. Thanks, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not possible to have joins on delete statements, but in most cases it's possible to come up with a subquery to use in
WHERE
that does the same thing. E.g. if you wanted to doDELETE FROM t1 JOIN t2 ON t2.foo = t1.bar WHERE t2.another = 3;
, you could instead do