PostgreSQL merge all tables together

I have four queries that brings data by network and a specific time period. I've done the math, now I need to visualize and put them together in a single query so they look tidy and accessible with a single query. Here are the result of these queries. How do I visualize them the best possible way?

I've used LEFT JOIN to show these time periods in a table btw

2022-08-18 15_22_55-murat_kpi_metrics _ Editor _ Retool
2022-08-18 15_23_18-murat_kpi_metrics _ Editor _ Retool
2022-08-18 15_23_34-murat_kpi_metrics _ Editor _ Retool
2022-08-18 15_24_29-murat_kpi_metrics _ Editor _ Retool

Try to use union or union all in query:

[query 1]
union all
[query 2]
union all
[query 3]
union all
[query 4]

Use union for not duplicate values and union all for duplicated values!

1 Like

Hey @caysle!

To add on to ssGabriel's comment, you might try using a Query JSON with SQL query here. This lets you pass in other query results or data from your app as a table to be queried.

For instance, you could use something like

select * 
  from {{formatDataAsArray(query1.data)}} as a 
  join {{formatDataAsArray(query2.data)}} as b on a.network = b.network 
  join {{formatDataAsArray(query3.data)}} as c on a.network = c.network
  join {{formatDataAsArray(query4.data)}} as d on a.network = d.network
1 Like