Skip to main content

I have a query with multiple CTEs and the various CTE's are joined.  I have successfully used 1 CTE in Tableau using initial SQL but have never faced a scenario like this with multiple CTEs.  Is this even possible?   

 

 

Thank you! 

 

 

 

#Tableau Desktop & Web Authoring

2 respostas
  1. 10 de set., 13:58

    @Luciana Suran

      

    Yes, it's absolutely possible — multiple CTEs use a SINGLE WITH keyword with the CTEs separated by commas (not a WITH per CTE), then you reference and join them in the final SELECT: WITH cte1 AS (...), cte2 AS (...), cte3 AS (...) SELECT ... FROM cte1 JOIN cte2 ON ... JOIN cte3 ON ... . Snowflake fully supports chaining CTEs like this, and a later CTE can reference an earlier one as long as you define them in dependency order. Since you're doing this in Initial SQL — which, unlike Custom SQL, is exactly where Snowflake temp tables are allowed — the clean pattern is to wrap the whole multi-CTE query in a temp table: CREATE OR REPLACE TEMPORARY TABLE my_stage AS WITH cte1 AS (...), cte2 AS (...) SELECT ... ; then just point your Custom SQL / data source at my_stage. That keeps the heavy joined-CTE logic on Snowflake and hands Tableau a simple flat table to read. if this helps, please mark it as the Best Answer so it helps the next person — thanks 🙂

0/9000