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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:47:50+00:00 2026-05-13T00:47:50+00:00

table a (t_a): id name last first email state country 0 sklass klass steve

  • 0
table a (t_a):
id  name    last    first   email           state   country
0   sklass  klass   steve   sklass@foo.com  in      uk
1   jabid   abid    john    abid@foo.com    ny      us
2   jcolle  colle   john    jcolle@foo.com  wi      us


table b (t_b):
id  sn      given   nick    email           l   c   
0   steven  klass   steve   sklass@foo.com  in  uk
1   john    abid    -       abid_j@foo.com  ny  us
2   johnny  colle   john    jcolle@foo.com  wi  us
3   john    abid    -       abid@foo.com    ny  us

What is listed above is an (abbreviated) column and row mySQL tables. Looking at the two tables it becomes pretty clear that by strictly looking at the values (id’s not looked at) and comparing the matching number of values you would get these value matches.

t_a     t_b
0       0
1       3
2       2
-       1

What I ultimately looking to do is to do this in Django — I’m not sure if that matters. In the past I have done this using pure python in which I destroy the old data and just create three new tables. I want to shift away from my implementation (listed below) because the problems I see is that time changes things and people come and go. In the past I have just regenerated the data — but now I want to keep track of when people leave and don’t simply replace (delete) the data. I believe that by doing a SQL update is more elegant and preserves the history.

I’d like to know how to get this merged answer directly from mySQL (Either a SQL function or the construction of a new table) which merges the data in the following manner. I want to do this using pure SQL (I believe then I can do this in Django). So I am looking for a solution which meets the following criteria:

  1. There is a min_match which defines the minimum number of matches between the two rows of which must be aligned to be considered valid.
  2. While the tables may have different lengths it is a 1-to-1 mapping. In other words many to one may not happen (yet)

Now my background is python and for me the simplest way to do this has always been to do a for loop over the shorter of the two tables, which then does a for loop over the other table looking at the number of matches. In code this looks like this.

t_a = [ ["sklass", "klass", "steve", "sklass@foo.com", "in", "uk", ],
        ["jabid", "abid", "john", "abid@foo.com", "ny", "us", ],
        ["jcolle", "colle", "john", "jcolle@foo.com", "wi", "us", ], ]

t_b = [ ["steven", "klass", "steve", "sklass@foo.com", "in", "uk",],
        ["john", "abid", "abid_j@foo.com", "ny", "us",],
        ["johnny", "colle", "john", "jcolle@foo.com", "wi", "us",],
        ["john", "abid", "abid@foo.com", "ny", "us",], ]

min_match = 3

for person_a in t_a:
    match = 0
    match_pct = 0.0
    match_a_index = t_a.index(person_a)
    for person_b in t_b:
        new_match_count = len(list(set(person_a) & set(person_b)))
        if new_match_count > match:
            match = new_match_count
            match_b_index = t_b.index(person_b)
            match_pct = "%.2f" % (float(new_match_count) / \
              float(len(set(person_a + person_b))) * 100)
    if match >= min_match:
        print match_a_index, match_b_index #, match_pct, match

The comments beg the question why don’t you just join on the email address. I don’t necessarily know that the values in a column will match. I am certain that values from a given row in t_a will match values for a row in t_b. I want the highest (most probable) match for a given row in t_a to t_b and only if the number of matches is higher than min_match.

  • 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-13T00:47:50+00:00Added an answer on May 13, 2026 at 12:47 am

    You can do this in MySQL directly via a cursor executed through a stored procedure.

    DELIMITER $$
    CREATE PROCEDURE `proc_name`()
    BEGIN
      DECLARE done INT DEFAULT 0;
      DECLARE a_id BIGINT UNSIGNED;
      DECLARE b_id BIGINT UNSIGNED;
      DECLARE x_count INT;
    
      -- something like the following
      DECLARE cur1 CURSOR FOR SELECT t_a.id, t_b.id FROM t_a, t_b WHERE t_a.email = t_b.email;
      DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
    
      SELECT COUNT(*) INTO x_count FROM t_a, t_b WHERE t_a.email = t_b.email;
    
      IF(x_count > <some_min_value>) THEN
    
        OPEN cur1;
    
        REPEAT
          FETCH cur1 INTO a_id, b_id;
          IF NOT done THEN
    
            -- do something here like update rows, remove rows, etc.
            -- a_id and b_id hold the two id values for the two tables which
            -- I assume to be primary keys
    
          END IF;
        UNTIL done END REPEAT;
    
        CLOSE cur1;
    
      END IF;
    END
    $$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a database with user's first name, last name, email, and temp password.
I have a table T with fields id, parentid , name. i make relationship
i have a table t_points in mySql like example in below. Name Surname Point
Possible Duplicate: Concatenate row values T-SQL I have a table like this: ref_num name
Here is some psuedo code for my table: List<IColumn<Foo>> columns = new ArrayList<IColumn<Foo>>(); columns.add(new
Let's say the following indexes my username and email colours of my users table
I'm working with MySQL and their last available JDBC driver, on a User table
Setup: mysql> create table t(a integer unsigned,b integer unsigned); mysql> insert into t(a,b) values
We have a table T which contains a several char(8) columns (implicitly) which under
i have a t_class table in mySql, in this table there are 3 columns,

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.