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 7569785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:15:13+00:00 2026-05-30T15:15:13+00:00

SQL joins have never been my strength. I would like some help with this

  • 0

SQL joins have never been my strength. I would like some help with this one. It is probably an easy one for you SQL maestros.

I have 2 tables with the same columns. Let’s say their structure is:

id INTEGER PRIMARY KEY AUTOINCREMENT,
key INTEGER,
description TEXT NOT NULL,
size INTEGER,
timestamp LONG,
is_on INTEGER

The table names are Shirts1 and Shirts2. The tables represent 2 versions of a dataset, and have a high amount of data overlap. The goal is to find which rows are different. key is the key which remains the same from version to version. Remaining columns can change from version 1 to 2.

Answers should be ideally for SQLite on Android. Multiple queries are OK – need not be 1 query.

My guess

SELECT * FROM Shirts1, Shirts2 WHERE Shirts1.key=Shirts2.key AND 
        (Shirts1.description != Shirts2.description OR 
        (Shirts1.size != Shirts2.size OR
        (Shirts1.timestamp != Shirts2.timestamp OR
        (Shirts1.is_on != Shirts2.is_on)

Another concern is would a query like this cause issues on an Android phone with limited device memory? There are 1000 rows in both tables. Should I break out the query into multiple queries, limiting comparison to 100 rows at at time for instance, as key goes from 1-1000 in order.

  • 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-05-30T15:15:14+00:00Added an answer on May 30, 2026 at 3:15 pm

    Shirt1:

    1;1;"green_shirt";1;1;1
    4;4;"yellow_shirt";1;1;1
    

    Shirt2:

    1;1;"green_shirt";1;1;1
    2;2;"red_shirt";1;1;1
    3;3;"orange_shirt";1;1;1
    
    
    
    SELECT shirt2.*
      FROM shirt1
      RIGHT OUTER JOIN shirt2 ON shirt1.key = shirt2.key
     WHERE shirt1.description != shirt2.description OR
           IFNULL(shirt1.size, -1) != IFNULL(shirt2.size, -1) OR
           IFNULL(shirt1.timestamp, -1) != IFNULL(shirt2.timestamp, -1) OR
           IFNULL(shirt1.is_on, -1) != IFNULL(shirt2.is_on, -1)      
     UNION ALL
    SELECT shirt1.*
      FROM shirt2
     RIGHT JOIN shirt1 ON shirt1.key = shirt2.key
     WHERE shirt1.description != shirt2.description OR
           IFNULL(shirt1.size, -1) != IFNULL(shirt2.size, -1) OR
           IFNULL(shirt1.timestamp, -1) != IFNULL(shirt2.timestamp, -1) OR
           IFNULL(shirt1.is_on, -1) != IFNULL(shirt2.is_on, -1)
     UNION ALL
    SELECT shirt1.*
      FROM shirt1
     INNER JOIN shirt2 ON shirt1.key = shirt2.key
     WHERE shirt1.description = shirt2.description OR
           IFNULL(shirt1.size, -1) = IFNULL(shirt2.size, -1) OR
           IFNULL(shirt1.timestamp, -1) = IFNULL(shirt2.timestamp, -1) OR
           IFNULL(shirt1.is_on, -1) = IFNULL(shirt2.is_on, -1)
    

    Output:

    2;2;"red_shirt";1;1;1
    3;3;"orange_shirt";1;1;1
    4;4;"yellow_shirt";1;1;1
    1;1;"green_shirt";1;1;1
    

    If you want to exclude the shirts that are included in shirt1/shirt2 you just have to remove the last union. That means

    SELECT shirt2.*
      FROM shirt1
      RIGHT OUTER JOIN shirt2 ON shirt1.key = shirt2.key
     WHERE shirt1.description != shirt2.description OR
           IFNULL(shirt1.size, -1) != IFNULL(shirt2.size, -1) OR
           IFNULL(shirt1.timestamp, -1) != IFNULL(shirt2.timestamp, -1) OR
           IFNULL(shirt1.is_on, -1) != IFNULL(shirt2.is_on, -1)      
     UNION ALL
    SELECT shirt1.*
      FROM shirt2
     RIGHT JOIN shirt1 ON shirt1.key = shirt2.key
     WHERE shirt1.description != shirt2.description OR
           IFNULL(shirt1.size, -1) != IFNULL(shirt2.size, -1) OR
           IFNULL(shirt1.timestamp, -1) != IFNULL(shirt2.timestamp, -1) OR
           IFNULL(shirt1.is_on, -1) != IFNULL(shirt2.is_on, -1)
    

    Output:

    2;2;"red_shirt";1;1;1
    3;3;"orange_shirt";1;1;1
    4;4;"yellow_shirt";1;1;1
    

    Think you will want everything in the same column so I think this should be the better solution. If you are ok with having different columns for shirt1/shirt2 then you can also use select * and ignore the union.

    About the device question: Depends on the device, but if the device is old then I don’t think that the query will be your main issue. You could also try to add a few indices to improve performance.

    Edit: changed the solution to join on the key column

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I never seen this, but is it possible to have one SQL call join
i have sql statement like this SELECT DISTINCT results_sp_08.material_number FROM results_sp_08 INNER JOIN courses
I am quite new at SQL statements and I have never been very good
I have a SQL Stored Procedure which is never ending because of some values
i have a general question about how sql server evaluates the joins.The query is
I wonder if anyone can help improve my understanding of JOINs in SQL. [If
Just learning about sql joins and things, and I have a question. Can you
I want to do a similiar thing like this guy: T-SQL Subquery Max(Date) and
I have been given the task of bringing three legacy systems together into one
We have a SQL server 2008 and one of the tables, say table A

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.