Php
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.
Reply to discussion (solution)
I'd better take a look at the code, dear.
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
NN, two tables in the columns are the same, but how to write, multi-column comparison, and then compare, the same deleted, not the same in the respective table, please, there is no detailed code for reference
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
But it's a little slow to ask for a high-performance rate.
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.
You can consider using stored procedures
Don't be so troublesome, send out the watch.
CREATE TABLE.
INSERT INTO..
And make a template out of the results you want.
The key now is how to delete the same data from the two tables and keep the different data?
Pro, give advice, best have code, thank you
You should give the test data.
For example:
The two tables are the same, now delete the same data and keep the different data
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.
Dear friends, Thank you for your support, with the help of everyone has been resolved
Delete A, a from a left JOIN B on A.c_num=b.c_num and A.c_jifen=b.c_jifen where a.c_num=b
. c_num