Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7864193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:42:38+00:00 2026-06-02T23:42:38+00:00

I have two tables in a Postgres database with identical structure and partly overlapping

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:42:40+00:00Added an answer on June 2, 2026 at 11:42 pm

    You could make a base table:

    class Table(models.Model):
       #some fields
       pass
    
    class Table1(Table):
       #some fields specific for table 1
       pass
    
    class Table2(Table):
       #some fields specific for table 2
       pass
    

    To obtain the table delta you may use:

    Table1.objects.exclude(id__in=Table2.objects.values_list('id', flat=True))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, the structure of the first partially recapitulates, iterates the structure
I have two Postgres databases. In one I have two tables, each with about
I have a table in an Openoffice Database, containing two date columns. I'm trying
I have two tables inside a database. One stores unique userNames and a unique
I have two tables with this structure: Table one: ID Description Table two: ID
I have two tables, I'll call TableA and TableB TableA: StartNumber EndNumber Country 1
I have two files that both work fine when executing them in Postgres. File
I have two tables (in postgres) - ads and logs. After every insert into
I have two tables (with the same schema) Table1 id title D0 D1 D2
Lets say I have two tables in Postgres: Name: table_rad Column Type id integer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.