Find all orders associated to the same customer ID

I know it's a very basic question, but being a noob at this, I really can't figure it out!
It's the very classic case of a Sales Dashboard. I have a Google Sheets file with a Customers data and another table with their orders.

I'm simply trying to show all the orders associated to a customer.

I have tried with filter and map functions but maybe I didn't put them in the right places? Or maybe I can do that with the manual filters of the tables?

Thank you so much for your help!!

Hey Alex! Welcome to the forum.

Without you sharing the schema of your Google Sheet, it's nearly impossible for anyone to help you towards a solution. Can you please create a Google Sheet in the exactly same structure as your real one, but with fake data?

// Jonathan

1 Like

Hi @Alex9000, welcome to the community :wave:

You can use the Query JSON with SQL resource for this one.
You have two sheets:

  • Customers Data (1 Gsheet read resource)
  • Orders Data (1 Gsheet read resource)

Call the above ones and join them in Query JSON with SQL and use something like this query:

SELECT
  cd.name,
  od.item_name,
  od.item_price,
  od.item_quantity
FROM {{ customerData.data }} cd
JOIN {{ orderData.data }} od ON cd.id = od.customer_id
WHERE cd.id = {{ select1.value }}

Reach out if you still have trouble implementing this one.

1 Like

Thank tou so much @jocen !
I'm terribly sorry but I don't really get the last line ...

WHERE cd.id = {{select1.value }}

What do you mean with select1.value ? I thought it would be something like cd.selectedRow.value ?

Thank you @jonathanbredo ! You're right, I didn't think of that :sweat_smile:
Next time I will post more details about what I want to achieve

Oh, wait! @jocen
it worked! I made a small variation:

SELECT
  cd.name,
  od.item_name,
  od.item_price,
  od.item_quantity
FROM {{ customerData.data }} cd
JOIN {{ orderData.data }} od ON cd.id = od.customer_id
WHERE cd.id = **{{cd.selectedRow.data.custid}}**