I have two tables in a Postgres database with identical structure and partly overlapping data, call them table1 and table2. I’m trying to calculate the delta by getting all the rows that are in one table but not the other. The queries I’m trying to run are roughly this:
SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2)
SELECT * FROM table2 WHERE id NOT IN (SELECT id FROM table1)
What is the best way to structure this in Django 1.4? Is there some way I can just have one model defined for both tables? What is the best way to query this information?
You could make a base table:
To obtain the table delta you may use: