MySQL old table deduplication data import new table and give primary key ID new value

Source: Internet
Author: User

Business Requirements:
A table has the Id,n1,n2,n3 field, which is a new empty table,

Table B has id,n1,n2,n3,n4,n5 fields, such as old tables containing data,

Now the record of the N1,N2,N3 combination in B table is re-imported into a table, and a table primary key is also entered value

Scenario: The records of B table after the query to go to the weight, while the results of the records are numbered, the sequence number as a table to insert the ID value, SQL statement as follows:

INSERT INTO A表(id,n1,n2,n3) select @row :[email protected]row+1 AS id,t1.* from (SELECT DISTINCT n1,n2,n3 FROM B表) t1,(select @row :=0) as t2

MySQL old table deduplication data import new table and give primary key ID new value

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.