Problems with database field matching

Source: Internet
Author: User
There are now two tables (MySQL)
Table 1 fields are as follows: Province, city, mobile number, name, other fields
Table 2 fields are as follows: Province, city, mobile number, other fields

Tables 1 and 2 of the database are larger, the daily new data millions of rows.
Table 1 and Table 2 are now divided into tables.
The requirement is to match two tables of data based on the phone number in the two tables.
The problem is:
1, the matching good data how to store, is stored in the third table, or in table 1 add a field, keep table 2 matches the ID of the row.
2. How to query for unmatched records.

Reply content:

There are now two tables (MySQL)
Table 1 fields are as follows: Province, city, mobile number, name, other fields
Table 2 fields are as follows: Province, city, mobile number, other fields

Tables 1 and 2 of the database are larger, the daily new data millions of rows.
Table 1 and Table 2 are now divided into tables.
The requirement is to match two tables of data based on the phone number in the two tables.
The problem is:
1, the matching good data how to store, is stored in the third table, or in table 1 add a field, keep table 2 matches the ID of the row.
2. How to query for unmatched records.

create table zzz(id int not null,xx ...,primary key(id)) as (select id, xx from table where ..)

Http://dev.mysql.com/doc/refm ...

Unmatched records, use one table as the left table to correlate the other table to determine if the right table has NULL
For example

select * from tb1left join tb2 on tb1.mobi=tb2.mobiwhere tb2.mobi is null

So the result is all the records in TB1 that don't appear in TB2.

But there is another situation in this case. If there is a record tb1 not present in the TB2, the TB1 's unmatched record cannot be detected.
In fact, to see whether the two tables are all matched can be used full join to match, but from the amount of your data, it is recommended not to use full join, even if you do not check all.

See this picture for join usage

Table optimization
1, mobile phone number word Jianjian index

2, sub-table recommendations according to mobile phone number of the first few to the table.

About storage

Table 1, table 2, is suggested to add fields to store rows from another table. You can skip the partial processing of the value of a field when the next update is processed.

What does not match is that the field is empty.

Other than that

It is recommended to put the update directly to the record, when adding data to table 1 when the query is present in table 2.

The query can be
SELECT * from t1,t2 where t1.mobile = T2.mobile
When the query comes out, you can create a new

  • 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.