How SQL Updates data when multiple fields are combined

Source: Internet
Author: User

Iamlaosong

When you update multiple fields in a table normally, the fields are written separately, for example:

Update Tb_county t   set t.prov_name = ' Anhui ', t.city_name = ' Hefei ', t.xs_mc = ' Luyang District ' where T.xs_code = ' 2300 ';

However, if the updated value comes from a subquery, these fields can be written together, for example:

Update Tb_county T   set (T.prov_name, T.city_name, T.XS_MC) = (select T.prov_name,                                                     t.city_name,                                                     T.XS_MC From                                                TB_YZBM t                                               where T.postcode = ' 230000 ') where T.xs_code = ' 2300 ';

Thus, we can rewrite the first statement to be:

Update Tb_county T   set (T.prov_name, T.city_name, T.XS_MC) = (select ' Anhui ',                                                     ' Hefei ',                                                     ' Luyang District ' from                                                dual) where T.xs_code = ' 2300 ';

This is not a good thing to do with human-computer interaction, but when you programmatically implement an UPDATE statement, it is much simpler to synthesize the UPDATE statement in such a format.



How SQL Updates data when multiple fields are combined

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.