Urgent! How to compare the content of two tables in the database, delete the same data, and retain different data
Source: Internet
Author: User
Urgent !! How to compare the content of two tables in the database, delete the same data, and keep different data urgently !!! I would like to explain how to compare the data in two tables and query them one by one. If the data is the same, query and delete one record; if the data is different, retain them separately. Finally, we will output the different data & nbsp; retained in the two tables and import them to another one for urgent use !! How to compare the content of two tables in the database, delete the same data, and retain different data
Please !!!
I would like to explain how to compare the data in two tables and query them one by one. If the data is the same, query and delete one record; if the data is different, retain them separately.
Finally, we will output the different data retained in the two tables and import them to another table that specifically stores the error. Share with PHP:
------ Solution --------------------
Is the data the same? Whether to judge based on a field or compare each field in the data table
All data in the two tables can be queried and compared cyclically.
------ Solution --------------------
The simplest way is to query all the data loops of a table and compare them with those of another table.
Another is directly join table query,
For example, select a, id, B. id from a, B where a. filed1 = B. filed1 and a. filed2 = B. filed2 and a. filed3 = B. filed3
The query is then deleted.
------ Solution --------------------
1. obtain the number of records in Table A. standby select count (*) as cnt from
2. extract the record select * from A union select * from B limit cnt, which is different from Table.
3. obtain the number of records in Table B. alternate select count (*) as cnt from B
4. extract the record select * from B union select * from A limit cnt from Table A, which is different from Table B.
What should I do later? You decide
------ Solution --------------------
You can consider using stored procedures.
------ Solution --------------------
Don't bother. send the table out,
Create table ..
Insert ..
Then make a sample of the result you want.
------ Solution --------------------
You should give 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
Then delete it.
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.