Forum Discussion

JustDavid's avatar
JustDavid
Icon for Helper V rankHelper V
2 years ago
Solved

Write SQL Query from an output tables of SQL

Hello,   I have 4 tables which is an output from Sql.Database ("server", "database", [Query=sql statement...])   I tried using the 'Merge Queries' function but the result is too slow to generate ...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi JustDavid ,

     

    From the description, the SQL statement looks similar to something like this:

     

    SELECT 
        t1.*, 
        t2.*, 
        t3.*, 
        t4.*
    FROM 
        (table1 sql statement) t1
    JOIN 
        (table2 sql statement) t2 ON t1.key = t2.key
    JOIN 
        (table3 sql statement) t3 ON t1.key = t3.key
    JOIN 
        (table4 sql statement) t4 ON t1.key = t4.key;

     

    You need to modify the JOIN type as well as the JOIN condition accordingly.

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

  • JustDavid's avatar
    JustDavid
    2 years ago

    Ray_Minds That's what I had. And in my original thread post above, I had 4 output tables.

     

    My question is that on a 5th table, I'd like to use SQL Statement to JOIN those 4 output tables. However before joining them, I'd need to further filter out unncessary data.

     

    If I were to use Power Query's 'Merge' built-in function, it's giving me very slow "refresh" (and thus output). Not to mention too that, I need to further filter out the 4 output tables. Thus the question if there's a possibility of using SQL instead of Power Query built-in 'Merge'.

     

    I guess the answer is no, and that I had to make all of my SQL statements into 1.