Update multiple rows in a table from another table when condition exists

后端 未结 3 938
说谎
说谎 2021-02-13 17:58

I have two tables.

Table1 contains companies whose locations are georeferenced with lat/lng coordinates in a column called the_geom

3条回答
  •  北海茫月
    2021-02-13 18:37

    I had a similar problem, but when I tried the solutions mentioned above, I got an error like

    Incorrect syntax near 't2'

    The code that worked for me is:

    UPDATE table2
    SET the_geom = t1.the_geom
    FROM table1 as t1
    WHERE table2.address = t1.address AND table2.the_geom <> t1.the_geom
    

    I know that my answer is 5 years late, but I hope this will help someone like me, who couldn't find this solution.

提交回复
热议问题