Hello i have a database question! join tables

Hi, I have a database query, if I have 2 different tables, how can I join them into one so that they come out in the same chronological order? I call the 2 tables with const query = new Moralis.Query("SalesCreated"); and const query = new Moralis.Query("BidsMade"); how can i join the 2? Thanks for the help

This may not be easy as the database is mongo db. You can try a pipeline or get the data from those 2 tables and join it after you already got the data

If this last option is what I think, I ask how I can join the 2 queries and return the 2 units in order by date, this is to create a cloud

how many rows are in those tables?
you could order them later if there are not too many

first table (SalesCreated) :

      attributes: {
        log_index: 44,
        transaction_hash: '0xff6c0f9a2c8f0dd059ce7c443fed432bad0af4c0f6b39a50f7cc1c22439182cf',
        createdAt: 2022-11-09T05:49:55.135Z,
        updatedAt: 2022-11-09T05:49:55.779Z,
        address: '0xe76bc6e52c2db6054c4e63f2c9e72ade240ac3de',
        block_hash: '0x3626107f76f4efc41d446bb2024e2934a637328fab209e63e11c009b9e1d6d13',
        block_number: 28930647,
        block_timestamp: 2022-11-01T21:40:06.000Z,
        buyNowPrice: '20000000000000000000',
        confirmed: true,
        erc20Token: '0x11142365ddbc92c3547b8a074289409b5432ca8b',
        feePercentages: [ '5' ],
        feeRecipients: [
          '0xb0A7c00EA503AdbdFE0071bdd9eB6Fbb18e7C6B5'
        ],
        nftContractAddress: '0x1c7d04c4ddee4d13c31e800568039aceabdcc3c8',
        nftSeller: '0x0bf75e9e3251fda1a66bd449c8630f16a2c3cabe',
        tokenId: '230',
        tokenId_decimal: {
          __type: 'NumberDecimal',
          value: { '$numberDecimal': '230' }
        },
        transaction_index: 19,
        whitelistedBuyer: '0x0000000000000000000000000000000000000000'
      },

second table (AuctionsCreated):

  attributes: {
    log_index: 66,
    transaction_hash: '0x0391a7b8fd0632cf9eae53c659724ae707bcb870036a21d6db85fe9642a307e8',
    createdAt: 2022-11-16T06:39:03.792Z,
    updatedAt: 2022-11-16T06:47:24.533Z,
    address: '0xe76bc6e52c2db6054c4e63f2c9e72ade240ac3de',
    block_hash: '0x483d0c89de03185d0be7ec352286ff9cdd9ccaccea640ee63fd505761274feda',
    block_number: 29178257,
    block_timestamp: 2022-11-16T06:39:03.000Z,
    buyNowPrice: '15000000000000000000',
    confirmed: true,
    erc20Token: '0x11142365ddbc92c3547b8a074289409b5432ca8b',
    feePercentages: [ '5' ],
    feeRecipients: [
      '0xb0A7c00EA503AdbdFE0071bdd9eB6Fbb18e7C6B5'
    ],
    nftContractAddress: '0x1c7d04c4ddee4d13c31e800568039aceabdcc3c8',
    nftSeller: '0x0bf75e9e3251fda1a66bd449c8630f16a2c3cabe',
    tokenId: '235',
    tokenId_decimal: {
      __type: 'NumberDecimal',
      value: { '$numberDecimal': '235' }
    },
    transaction_index: 13,
    whitelistedBuyer: '0x0000000000000000000000000000000000000000'
  },

I mean how many rows they have or how many they are expected to have

you can also do a limit based on the date

I need the same amount of the table AuctionsCreated, and the same fields

maybe this helps

https://www.back4app.com/docs/react/data-objects/react-join-query

thank you i will go read

from what I could read it is something like this:

Moralis.Cloud.define('getNftPageActivity', async function(){

  const queryAuction = new Moralis.Query("AuctionsCreated");

  const querySales = new Moralis.Query("SalesCreated");

  querySales.matchesQuery("join", queryAuction);

  querySales.include("join");

  const results = await querySales.find({ useMasterKey: true });  

 

  return results

});

but it does not return anything

after reading now that post, it seems more complicated, it looks like they created a link from one table to the other table

// Create TableA and its records
let TableARecord1 = new Parse.Object('TableA');
TableARecord1.set('FieldA', 'Value A 1');
TableARecord1 = await TableARecord1.save();

// Create TableB and its records, some of them linked to TableA
let TableBRecord1 = new Parse.Object('TableB');
TableBRecord1.set('FieldB', 'Value B 1');
TableBRecord1.set('link', TableARecord1);
TableBRecord1 = await TableBRecord1.save();