Emergency! How to compare the contents of two tables in a database, delete the same data, and keep different data

Source: Internet
Author: User
Emergency!! How to compare the contents of two tables in a database, delete the same data, and keep different data
URGENT Request!!!

Excuse me, how to compare the data in two tables. If the data is the same, check one article and delete it, if the data is different, keep it separately.

Finally, the different data from the two tables is exported and imported into another table dedicated to the error. PHP

Share to:


------Solution--------------------
is the data the same? is judged by a field, or if each field in the datasheet is compared
You can query out all the data in both tables, and cycle through the comparison
------Solution--------------------
Oh, the simplest way is to query a table all the data loop comparison with another table

There is also a direct linked table query,
For example select A,id,b.id from a, where a.filed1=b.filed1 and A.filed2=b.filed2 and A.FILED3=B.FILED3

This query then deletes the
------Solution--------------------
1. Obtain the record number of table a standby select COUNT (*) as CNT from A
2. Extract the records of table B different from table a select * FROM A Union SELECT * FROM B limit CNT
3. Get the number of records in table B spare select COUNT (*) as CNT from B
4. Extract the records of table A different from table B select * FROM B Union SELECT * FROM A limit CNT

What do you do back there? You decide for yourself.
------Solution--------------------
You can consider using stored procedures
------Solution--------------------
Don't be so troublesome, send out the watch.
CREATE TABLE.
INSERT INTO..

And make a template out of the results you want.
------Solution--------------------
You should give the test data.
------Solution--------------------
Select A,id,b.id from a b where a.filed1=b.filed1 and A.filed2=b.filed2 and A.FILED3=B.FILED3
And then delete it.
  • 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.