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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:03:05+00:00 2026-05-26T01:03:05+00:00

I’ve been trying to figure out the best way to write a query to

  • 0

I’ve been trying to figure out the best way to write a query to compare the rows in two tables. My goal is to see if the two tuples in result Set A are in the larger result set B. I only want to see the tuples that are different in the query results.

'''SELECT table1.field_b, table1.field_c, table1.field_d
'''FROM table1
'''ORDER BY field_b

results_a = [(101010101, 111111111, 999999999), (121212121, 222222222, 999999999)]

'''SELECT table2.field_a, table2.fieldb, table3.field3
'''FROM table2
'''ORDER BY field_a

results_b =[(101010101, 111111111, 999999999), (121212121, 333333333, 999999999),    (303030303, 444444444, 999999999)]

So what I want to do is take results_a and make sure that they have an exact match somewhere in results_b. So since the second record in the second tuple is different than what is in results_a, I would like to return the second tuple in results_a.

Ultimately I would like to return a set that also has the second tuple that did not match in the other set so I could reference both in my program. Ideally since the second tuples primary key (field_b in table1) didn’t match the corresponding primary key (field_a) in table2 then I would want to display results_c ={(121212121, 222222222, 999999999):(121212121, 222222222, 999999999)}. This is complicated by the facts that the results in both tables will not be in the same order so I can’t write code that says (compare tuple2 in results_a to tuple2 in results_b). It is more like (compare tuple2 in results_a and see if it matches any record in results_b. If the primary keys match and none of the tuples in results b completely match or no partial match is found return the records that don’t match.)

I apologize that this is so wordy. I couldn’t think of a better way to explain it. Any help would be much appreciated.

Thanks!

UPDATED EFFORT ON PARTIAL MATCHES

a = [(1, 2, 3),(4,5,7)]
b = [(1, 2, 3),(4,5,6)]
pmatch = dict([])

def partial_match(x,y):
    return sum(ea == eb for (ea,eb) in zip(x,y))>=2

for el_a in a:
    pmatch[el_a] = [el_b for el_b in b if partial_match(el_a,el_b)]
print(pmatch)

OUTPUT = {(4, 5, 7): [(4, 5, 6)], (1, 2, 3): [(1, 2, 3)]}. I would have expected it to be just {(4,5,7):(4,5,6)} because those are the only sets that are different. Any ideas?

  • 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-26T01:03:05+00:00Added an answer on May 26, 2026 at 1:03 am

    Take results_a and make sure that they have an exact match somewhere in results_b:

    for el in results_a:
      if el in results_b:
         ...
    

    Get partial matches:

    pmatch = dict([])
    def partial_match(a,b):
      # for instance ...
      return sum(ea == eb for (ea,eb) in zip(a,b)) >= 2
    for el_a in results_a:
      pmatch[el_a] = [el_b for el_b in results_b if partial_macth(el_a,el_b)]
    

    Return the records that don’t match:

    no_match = [el for el in results_a if el not in results_b]
    

    — EDIT / Another possible partial_match

    def partial_match(x,y):
      nb_matches = sum(ea == eb for (ea,eb) in zip(x,y))
      return 0.6 < float(nb_matches) / len(x) < 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have two tables with like below codes: Table: Accounts id | username |
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.