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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:20:57+00:00 2026-06-15T06:20:57+00:00

I have two tables holding game data for two different games. For the sake

  • 0

I have two tables holding game data for two different games. For the sake of simplicity, let’s say they only share a column called Timestamp (in particular they have a different number of columns). I want to render a list holding information from both tables, simultaneously ordered by Timestamp.

What I’m currently doing works, but I’d take almost any bet that there is a much better way to do this. I’m mostly concerned about performance at some point (mobile app). This is a stub representing the structure – believe me, I know how horrible this looks right now. I just wanted to make it work first, now I’m looking for improvements. 😉

var readyA,
    readyB = false;

var dataA, 
    dataB;

function doLoop () {
    setTimeout(renderData, 100);
}

function renderData () {
    if (!readyA || !readyB) {
        doLoop();
        return;
    }

    var dataAll = dataA.concat(dataB);
    dataAll.sort(function (a,b) {
        return a['Timestamp'] <= b['Timestamp'];
    });

    // pass data into a template depending on from which game it is and render it
    // ...
}

// wait for both queries to finish
doLoop();

// select data from game A
myDatabaseClass.query('SELECT ... FROM GameA', function (results) {
    dataA = new Array(results.rows.length);
    for (var i=0; i<results.rows.length; i++) { 
        dataA[i] = results.rows.item(i); 
    }

    readyA = true;
});

// select data from game B
myDatabaseClass.query('SELECT ... FROM GameB', function (results) {
    dataB = new Array(results.rows.length);
    for (var i=0; i<results.rows.length; i++) { 
        dataB[i] = results.rows.item(i); 
    }

    readyB = true;
});

The question would now be if I can somehow simplify this by some kind of UNION or JOIN in the query. Obviously, the Timeout construction is horrible, but that will automatically collapse to a simple callback function if the querying can be done in one query (or at least one transaction – the database class can handle that).

Edit: I did found this ( Pull from two different tables and order ) but this whole NULL AS some_column feels dirty. Is there really no better alternative?

  • 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-15T06:20:59+00:00Added an answer on June 15, 2026 at 6:20 am

    Your code is pretty good. From the point of view of a SQL hacker like me you’re doing the UNION and the ORDER BY on the client side. There’s nothing wrong with that. You seem to be doing it almost right. Your “concat” is the client-side equivalent of UNION, and your “sort’ is the equivalent of ORDER BY.

    You say that the NULL as missing-column construction feels somehow dirty if you use server-side UNION operations. But, obviously to treat two different result sets as the same so you can sort them in order you have to make them conform to each other somehow. Your a['Timestamp'] <= b['Timestamp'] sort-ordering criterion in your sort function is also a scheme for conforming two result sets to each other. It may be lower-performance than using a UNION.

    Don’t be afraid of using NULL as missing-column to make two result sets in a UNION conform to each other. It’s not dirty, and it’s not expensive.

    Do consider limiting your SELECT operation somehow, perhaps by a range of timestamps. That will allow your system to scale up, especially if you put an index on the column you use to limit the SELECT.

    (By the way, your sort function has a mistake in it. sort functions need to return -1, 0, or +1 depending on whether the first item is less than, equal to, or greater than the second one. You’re returning a true/false value. That doesn’t work properly.)

    (You’re parallelizing the two queries to the same MySQL instance. That’s clever, but probably in truth is a formula for overloading MySQL as your game scales up. Keep in mind that each user of your game has her own machine running Javascript but they all share your MySQL.)

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

Sidebar

Related Questions

Have two tables say ABC and XYZ and contain one column which data will
I have two tables: users and user_depts. Let's say (for this question) that users
I have two tables. One is holding the titles of games. Another is holding
Have have two tables in two different databases: Lets say i have Database users
I have two tables, lets say table1 and table2 with common columns, id and
When I have two mysql servers that have different jobs (holding different databases) but
I have two tables: Holdings and Transactions Holdings data looks like: 06/30/2009, A, 100
I have two tables. Table1 is our main table of data and Table2 has
I have two tables: one holding products and one holding related inventory moves. Product
The database I am working with currently does have two tables, one holding the

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.