Mysql Data Tables are merged and only one duplicate data is read.

Source: Internet
Author: User
Tags mysql tutorial

In the mysql tutorial, data tables are merged and only one duplicate data is read.
// First, let's take a look at the mysql SQL structure and use union Joint queries and insert into to replicate the whole table.

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 the encoding of the document and the database tutorial to be consistent. Otherwise, garbled characters may occur.

/*
First, create tables a111cnnet, b111cnnet, and c111cnnet. Now I want to import b111cnnet and c111cnnet to a111cnnet. If the two tables have the same records, only one record is saved.
 
The structure of the three tables is the same as follows:
Id mediumint (8) UNSIGNED no 0
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 query
*/
 
$ 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
 
Analysis
Insert into full table Import
Union Joint Query
 
The original article on this site is reprinted to indicate that it is from www. bKjia. c0m
*/

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.