Sqlyog - multiple SQL queries - sqlyog

I have set of SQL select queries to execute and share the consolidated results in excel sheet, I'm using sqlyog to do this.
Every time I execute results are in multiple tables. Can I get the results in a single table?
Select * from a.table;
Select * from b.table;

To get the result in a single table you need to use JOIN's in your query.
For Example, I have a area_table and I have a height_table.
to get the result in the consolidated table I would use JOIN and write the query as:
Select a.*,b.* from area_table a
Join height_table b;

Related

How to see results of multiple SQL queries in Databricks?

I have a cell with multiple SQL queries like MERGE, SELECT etc. When I run the notebook through a workflow TASK I can see the output of the last run SQL query for a particular cell only. How to see output for each queries?

I'm using power automate to query an access database and I want to know how to return the query headers to my output

I'm directly querying a local access database using power automate desktop. I'm performing an sql query directly into access by way of an open sql connection in power automate rather than pulling data from a stored results table. When I write the query results to an excel file in the same flow I get my results but not the result column headers. I've looked through most of the answers provided here and they all suggest MySQL, SQL server, or other solutions that I simply don't have.
My current query looks like:
SELECT table1.uid, table2.[job.title], table1.[start.date],
table1.[end.date], table2.company, table1.role, table2.active
FROM table1 INNER JOIN table.2 ON table1.uid=tables.uid
And so when I run the query my column headers are UID, job title, start date, end date, company, role, active.
I'd like those headers generated by the query to carry over to the Excel sheet so I don't have to manually insert them.
In short can I write an sql query that directly connects to access through an open sql connection in power automate and have it return the data and the data column headers?

Excel: Create or Replace Table statement not working in Excel Get Data From OBDC

I have a set of queries that are pulling data into my Excel workbook. I'm using the "Get Data from OBDC" feature in Excel. All of my data pulls are SELECT statements and they run fine.
I also want to add a query that "CREATE or REPLACE TABLE" in the Excel workbook so I don't have to go to GBQ separately to run this query. Is there anyway to do this in Excel?
Below is the code I am running...
CREATE OR REPLACE TABLE table_A as(
SELECT
item_a,
item_b,
item_c
FROM table_B
)
ERROR I'm getting: "This native database query isn't currently supported."
Is there a way to use an Create or Replace statement in the Excel Get Data from OBDC feature?

Alternative to External Table Join in Azure Database

I have currently setup multiple Azure DBs on a single server primarily with different schemas.
External Queries work perfectly fine on small tables. I am currently using an INNER JOIN on multiple tables within 2 DBs.
This works great for small tables with limited data sets since it appears to be physically copying the tables over to a temp table then performing the query.
However when I do a join on a large table ~500K rows the query will fail as the size of the table causes a timeout while it tries to copy the table to the temp directory.
Is there a way to execute the query without copying the JOIN table to a temp directory?
I have previously tried to create Stored procedures on the DB with the Large Table I am trying to join, however that DB will eventually be sunset and I will be back where I am now so I would like a longer term solution.
Alternately consider consolidating your separate databases into one single database, eg using schemas to provide separation. Ask yourself the question "Why are my databases split?" or is having to join across them an occasional thing? Do you need them to be split. If having to join across them is a regular task then consolidating them makes sense.
Alternately consider Managed Instance. This is a PaaS service but gives you an experience closer to traditional SQL Server. First off, you can have multiple databases in once instance and cross-database joins are as easy as they are in box product SQL Server.
I ended up using a CROSS APPLY (Inner Join) and OUTER CROSS APPLY (Left Join) then adding the logic to a where statement within
Select c.Id, a.Quantity, b.Name
From Table1 a CROSS APPLY
(Select * FROM Table2 WHERE x = y) c
INNER JOIN Table3 b ON c.x = b.x
Add Join
Add Join
This executed the joins on the target without having to bring the whole table into a TempTable.

Incorporate a local data set in Excel Power Query against SQL Server

Business Case:
I have a list of key IDs in an excel spreadsheet. I want to use Power Query to join these IDs with a details table in a SQL Server database.
Problem
Currently using Power Query I only know how to import the entire table, which is greater than 1 million records, then do a left join on it against an existing query that targets a local table of IDs.
What I want to do is send that set of IDs in the original query so I'm not pulling back the entire table and then filtering it.
Question
Is there an example of placing an IN clause targeting a local table similar to what is shown below?
= Sql.Database("SQLServer001", "SQLDatabase001",
[Query="SELECT * FROM DTree WHERE ParentID
IN(Excel.CurrentWorkbook(){[Name="tbl_IDs"]}[Content])"])
I would first build a "Connection only" Query on the excel spreadsheet key IDs.
Then I would start a new Query by connecting to the SQL table. In that query I would add a Merge step to apply the key IDs query as an Inner Join (filter).
This will download the 1m rows to apply the filter, but it is surprisingly quick as this is mostly done in memory. It will only write the filtered result to an Excel table.
To improve performance, filter the rows and columns as much as you can before the Merge step.

Resources