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.