0

My use case is to build a dashboard from different SQL queries, but the problem is that i have let's say 50 widgets (50 different select statements) that can omit totally different results (either one value, or several rows, etc..)

As my DB is Amazon Timestream - I cannot do 50 queries because each query will cost me 10MB (this is the minimum charged per query).

I wanted to try and combine all queries into one, and pay only on one scan, but i'm not sure how to combine unrelated queries into one, and parse the results according to it.

The goal is to have different queries (let's say i'm calculating count_val, max_val and multi rows response such as "items") so i wanted to have a result like this:

max_val count_val items
50 null null
null 100 null
null null item1
null null item2
null null item3

This way i can loop the rows and only the relevant ones will contain my values, so i can create a dashboard.

So if let's say one statement has 200 rows, and other statements has 100 rows, there will be 300 rows in the results (with null in respected columns)


Solved it using

Select * from
(QUERY 1)
FULL OUTER JOIN
(QUERY 2)
ON 1 = 0
FULL OUTER JOIN
(QUERY 3)
ON 1=0
ArielB
  • 1,184
  • 2
  • 11
  • 36
  • How does amazon-timestream bill `UNION ALL`? I would think it still considers them as separate, but have never used that service but think it's worth confirming. – Isolated Oct 31 '22 at 13:56
  • it's the amount of scan, Actually i think i solved it using FULL OUTER JOIN – ArielB Oct 31 '22 at 14:13

1 Answers1

0

Whoever searches for this

Select * from
(QUERY 1)
FULL OUTER JOIN
(QUERY 2)
ON 1 = 0
FULL OUTER JOIN
(QUERY 3)
ON 1=0
ArielB
  • 1,184
  • 2
  • 11
  • 36