PostgreSQL Two-table junction update

Source: Internet
Author: User

PostgreSQL Two-table joint update
Recently use PostgreSQL feel a bit useless, a joint update is not to write this syntax to:
Update D_routetrip
Set Name=b.name,
Description=b.description
From D_scenery as B
where foreignid=b.id and d_routetrip.type= ' scenery '

As mentioned above, and before the D_routetrip table can not alias, set after the application of the table is also directly represented by the field, do not need to refer to the alias or syntax error, and the fields referenced in and after must indicate which table belongs to, otherwise also error. The use of good nerves
The common SQL two-table joint update is much simpler, as follows:
Update Table1
Set TABLE1.CO1=TABLE2.CO1,
Table1.co2=table2.co2
From Table2
where table2.id=table1.id

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.