Update with inner join?

Hey folks, is it possible to do an update with an inner join in order to have more complicated filter logic, with values coming from other tables, for our where?
5 Replies
Angelelz
Angelelz12mo ago
So, you need to run an update statement with values from other tables? Can you elaborate what you're trying to accomplish?
xeon06
xeon06OP12mo ago
Sure! Essentially I want to update records with a WHERE clause that references another table Typically in SQL I'd do UPDATE entity INNER JOIN users ON users.id = entity.userId SET thing = 2 WHERE user.country = "CAN" For instance, just typed from my phone That or a subquery but doesn't look like that's possible in Drizzle either So for now I'm doing two queries, one to get user IDs with the country and then an inArray... Not great
Angelelz
Angelelz12mo ago
You can put a subquery in inArray This is possible in one query Just not with the join, has to be a subquery in the where clause
xeon06
xeon06OP12mo ago
I'm just worried about the performance of a large inArray, but maybe I shouldn't?
Angelelz
Angelelz12mo ago
Yeah, that's up for debate. Drizzle doesn't support update join statements yet, so you'll have to write this in raw
Want results from more Discord servers?
Add your server