I have two tabels with a relation and I want to update a field in table A. Is it possible to combine update and join in the same query? I googled it but didnt find any working s
The Left join in this query is pointless:
UPDATE md SET md.status = '3'
FROM pd_mounting_details AS md
LEFT OUTER JOIN pd_order_ecolid AS oe ON md.order_data = oe.id
It would update all rows of pd_mounting_details
, whether or not a matching row exists in pd_order_ecolid
. If you wanted to only update matching rows, it should be an inner join.
If you want to apply some condition based on the join occurring or not, you need to add a WHERE
clause and/or a CASE
expression in your SET
clause.