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

  • Home
  • SEARCH
  • 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 786719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:05:15+00:00 2026-05-14T21:05:15+00:00

I have two tables on different servers, and I’d like some help finding an

  • 0

I have two tables on different servers, and I’d like some help finding an efficient way to combine and match the datasets. Here’s an example:

From server 1, which holds our stories, I perform a query like:

query = """SELECT author_id, title, text
           FROM stories
           ORDER BY timestamp_created DESC
           LIMIT 10
           """
results = DB.getAll(query)

for i in range(len(results)):
    #Build a string of author_ids, e.g. '1314,4134,2624,2342'

But, I’d like to fetch some info about each author_id from server 2:

query = """SELECT id, avatar_url
           FROM members
           WHERE id IN (%s)
           """
values = (uid_list)
results = DB.getAll(query, values)

Now I need some way to combine these two queries so I have a dict that has the story as well as avatar_url and member_id.

If this data were on one server, it would be a simple join that would look like:

SELECT *
FROM members, stories
WHERE members.id = stories.author_id

But since we store the data on multiple servers, this is not possible.

What is the most efficient way to do this? I understand the merging probably has to happen in my application code … any efficient sample code that minimizes the number of dict loops would be greatly appreciated!

Thanks.

  • 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-14T21:05:16+00:00Added an answer on May 14, 2026 at 9:05 pm

    If memory isn’t a problem, you could use a dictionary.

    results1_dict = dict((row[0], list(row[1:])) for row in results1)
    results2_dict = dict((row[0], list(row[1:])) for row in results2)
    
    for key, value in results2_dict:
        if key in results1_dict:
            results1_dict[key].extend(value)
        else:
            results1_dict[key] = value
    

    This isn’t particularly efficient (n2), but it is relatively simple and you can tweak it to do precisely what you need.

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

Sidebar

Related Questions

No related questions found

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.