MySQL Update Select usage instance

Source: Internet
Author: User
Tags mysql update

MySQL Update Select usage instance

You should use the inner join, which is:

UPDATE Friends INNER JOIN users on Friends.friendid=users.userid SET friends.friendname=users.username

MySQL uses a temporary table to implement a nested query inside the FROM clause, then the nested query is loaded into another nested query, so that the FROM clause query and save are in the temporary tables, and then indirectly in the perimeter query is referenced.

Let's look at the following SQL statement:

Update apples

Set price = (

Select Price from (

SELECT * from apples

) as X

where variety = ' Gala ')

where variety = ' Fuji ';

Continue to look at the following two examples

Update a set a.xx= (select yy from B) where a.id = b.ID;

However, in MySQL, you cannot use the result of a set select directly, you must use the INNER join:

Update a INNER join (select yy from B) C on a.id =b.id set a.xx = C.yy

The following is a classic MySQL UPDATE statement assignment nested Select instance

Update mem_player set ' datawarehouse ' = (select ' Datawarehouse ' from (SELECT * from Mem_player) as B where ' Pid ' =100000)

        Note : More wonderful articles please pay attention to the triple programming Tutorial column.

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.