skip to Main Content

I have made 2 test databases to reflect my problem of trying to find what rows are missing in the old table in old database, that are present in the new table in new database.

MariaDB [(none)]> SELECT * FROM DBNEW.items;
+---------+------+
| mainKey | data |
+---------+------+
|       1 |  100 |
|       2 |   99 |
|       3 |  101 |
|       4 |  100 |
+---------+------+

MariaDB [(none)]> SELECT * FROM DBOLD.items;
+---------+------+
| mainKey | data |
+---------+------+
|       1 |  100 |
|       2 |   99 |
|       4 |  100 |
+---------+------+

I tried these queries so far. First 2 give syntax errors and 3rd returns no results even if second SELECT is in parenthesis:

SELECT * FROM DBNEW.items
EXCEPT
SELECT * FROM DBOLD.items

SELECT * FROM DBNEW.items
INTERSECT
SELECT * FROM DBOLD.items

SELECT * FROM DBNEW.items
WHERE NOT EXISTS
SELECT * FROM DBOLD.items

Trying the following did a working intersection but I don’t know how to get only differences as using != will combine every row from one DB with every row in another.

SELECT * FROM DBNEW.items AS newI, DBOLD.items AS oldI
WHERE newI.mainKey = oldI.mainKey

2

Answers


  1. select * from DBNEW.items where mainkey not in ( select mainkey from DBOLD.items)

    Login or Signup to reply.
  2. SELECT * FROM DBOLD.items where mainKey not in (SELECT mainkey FROM DBNEW.items )
    

    this will give data missing in DBOLD

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search