Moralis select rows by creation date and avoid duplicate colums

Hi, I have a Moralis query, the underlying table tracks my Marketplace.
If an item gets listed more than once, I will have two rows for it.
So I want to filter the query so that the returned array of objects only contains the combination of “nftContract” and “tokenId” once and that the combination returned is the one with the newest createdAtDate.

Currently I fetch from the db like this:


  const getItems = async (asdf) => {
    Moralis.start({
      serverUrl,
      appId,
    })
    const query = new Moralis.Query('')
    query.equalTo('asdf', asdf)
    const items = JSON.parse(JSON.stringify(await query.find()))
    return items
  }

Any suggestions?

You can add one more query.equalTo after this line.

Thanks, can I also sort the response somehow by creationDate?

You can use query.ascending("columnName") / query.descending("columnName") to sort.

But not sure if it works with date string

you can find examples here in documentation also:
https://docs.moralis.io/moralis-dapp/database/queries

Thanks, that should solve the basics of that, I can then still filter out the duplicate entries after querying. Topic could be marked as solved from my side.