MySQL data table merge and only duplicate data read only one

Source: Internet
Author: User
Tags mysql tutorial

MySQL Tutorial datasheet merge and only duplicate data read only one
First we have to shield MySQL SQL structure, with union query and insert into to the whole table copy.

mysql_connect ("localhost", "root", "root") or Die (' Database Server Uid or Password error! ');
mysql_select_db (' IP ') or die (' Data! ');
mysql_query ("Set NAMES ' gb2312 '");/Set document and database tutorial code is OK, otherwise it will be garbled

/*
  First we create the datasheet a111cnnet and b111cnnet,c111cnnet  table, and now I'm going to import b111cnnet,c111cnnet into the A111cnnet table. And if two tables have the same record, save only one. The structure of the
 
  Three tables is the same as the following
   ID mediumint (8)    UNSIGNED no 0    & nbsp;          
   FID smallint (6)    UNSIGNED No 0               
    Allowview tinyint (1)    no 0                
   allowpost tinyint (1)    no 0                
   allowreply

Table B111cnnet Records
1,2,3,6,4
2,3,6,5,4

Table C111cnnet Records
1,2,3,4,5
4,6,5,2,8

Now let's check it out.
*/

$sql = "INSERT INTO a111cnnet (SELECT * from b111cnnet) union (SELECT * from C111cnnet)) as TT GROUP BY ID) ";

mysql_query ($sql);//The result is

/*
Table A111cnnet Records

1,2,3,4,5
2,3,6,5,4
4,6,5,2,8

Analytical
Insert into full table import
Union Union query

This site original article reproduced annotated from Www.111cn.net
*/

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.