Reputation: 62366
I'd like to select from one table and use the results of that select to update another table, but only based on certain conditions. Is this possible with a 1-time SQL query?
Upvotes: 0
Views: 100
Reputation: 62369
Yes it is.
UPDATE
tableToUpdate AS ttu
[LEFT|RIGHT|INNER] JOIN
otherTable AS ot
ON
joinCondition
SET
ttu.field = ot.field
WHERE
conditionsToBeMet
AS otherTable
you can just use the SELECT
query that you use to fetch your resultset.
Upvotes: 2