UPDATE statement with multiple joins in PostgreSQL

前端 未结 5 1801
说谎
说谎 2021-01-07 18:16

I\'m trying to update a table called incode_warrants and set the warn_docket_no to the viol_docket_no from the incode_violations

5条回答
  •  抹茶落季
    2021-01-07 18:55

    Your query should look like this:

    UPDATE incode_warrants
    SET warn_docket_no = incode_violations.viol_docket_no
    FROM incode_violations
    WHERE incode_violations.viol_citation_no = incode_warrants.warnv_citation_no
    AND incode_violations.viol_viol_no = incode_warrants.warnv_viol_no;
    

    You don't need any other join. With this query you just update a column in one table with values from a column from another table. Of course, it updates only when WHERE condition is true.

提交回复
热议问题