MySQL two table same ID match, output to new table, delete old table match

Source: Internet
Author: User
Tags one table

0x00: Preface.

There are two tables, one table field is Id-email, the other table field is ID-PWD, you want to merge the two tables with SQL script, because the same ID can match.


0x01: Example.

A field Id:email

650) this.width=650; "src=" Https://s5.51cto.com/oss/201711/13/5862387deaaa4307156e3147caa6e2f7.png "style=" float: none; "title=" Email.png "alt=" 5862387deaaa4307156e3147caa6e2f7.png "/>

Another field is Id:pwd

650) this.width=650; "src=" Https://s5.51cto.com/oss/201711/13/18816f1c5a263666ee374f63a16b0909.png "style=" float: none; "title=" Pwd.png "alt=" 18816f1c5a263666ee374f63a16b0909.png "/>


The desired output is the result ID:Email:PWD

650) this.width=650; "src=" Https://s2.51cto.com/oss/201711/13/eb848a705359845706c5ae04a790f6ce.png "style=" float: none; "title=" Out.png "alt=" Eb848a705359845706c5ae04a790f6ce.png "/>



The 0x02:mysql statement.

Note: Because MySQL is safe, one line is not allowed to execute two statements (for example: Linux under &&).

Writes the statement to the SQL script file before execution, and the file suffix with. sql,tttt_test is the database name.

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201711/13/ccf410d7798d3df1375220ace613bcbf.png-wh_500x0-wm_3 -wmp_4-s_3857505506.png "title=" Out_test.png "alt=" Ccf410d7798d3df1375220ace613bcbf.png-wh_ "/>

The following is the text.

CREATE TABLE OUT1 as SELECT a.id,a.email,b.pwd from e-mail a INNER JOIN pwd b on a.id = B.id;delete A, from email a INNER JOIN pwd b on a.id = b.ID;


This article is from the "Enlightened Grocery store" blog, please be sure to keep this source http://wutou.blog.51cto.com/615096/1981338

MySQL two table same ID match, output to new table, delete old table match

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.