MySql Subtract a table from another

I have two tables: A contains all the data, table B created from A selects% 25 of its data randomly. Thus, A and B have the same columns. Also there is no unique column.

What I want to do is subtract B from A. Any ideas?

+5
source share
5 answers

To view all lines in Aexcept those specified in B:

SELECT * FROM A
WHERE (field1, field2, ..., fieldN) NOT IN
( SELECT *
  FROM B
) ;

To actually remove from the table Arows that are in B:

DELETE FROM A
WHERE (field1, field2, ..., fieldN) IN
( SELECT *
  FROM B
) ;
+8
source

Given that you are comparing multiple fields, you need to either use the existing one or join. since you want to remove its simpler yi just use.

        delete from
        Tablea
        Where
         Exists(
              Select 1 
               from tableb
              where tablea.fielda = tableb.fielda 
                    And tablea.fieldb = Tableb.fieldb
                   And...)
+1

, , , B - A. :

SELECT * FROM A WHERE NOT EXIST 
 (SELECT * FROM B WHERE A.field1 = B.field1 AND A.field2 = B.field2 etc)

, A B.

+1

( ) , (25% )

0

, , :

WHERE a.c1 = (SELECT c1 FROM b) a.c2 = (SELECT c2 FROM b) a.c3 = (SELECT c3 FROM b)

, , ...

Well, then the only thing I got is to make an identifier column, sorry ...

0
source

All Articles