| title | Query the Warehouse or SQL analytics endpoint |
|---|---|
| description | Learn more about options to write T-SQL queries on a warehouse or SQL analytics endpoint in Microsoft Fabric. |
| ms.reviewer | prlangad |
| ms.date | 01/06/2026 |
| ms.topic | how-to |
| ms.search.form | Query editor |
Applies to: [!INCLUDE fabric-se-dw-mirroreddb]
In this article, learn how to query a warehouse or a SQL analytics endpoint in Microsoft Fabric.
To get started with this tutorial, check the following prerequisites:
-
You should have access to a [[!INCLUDE fabric-se]](data-warehousing.md#sql-analytics-endpoint-of-the-lakehouse) or [[!INCLUDE fabric-dw]](data-warehousing.md#fabric-data-warehouse) within a Premium capacity workspace with contributor or higher permissions.
-
Choose your querying tool.
- Use the [SQL query editor in the [!INCLUDE product-name] portal](sql-query-editor.md).
- Use the [Visual query editor in the [!INCLUDE product-name] portal](visual-query-editor.md).
-
Alternatively, you can use any of these tools to connect to your [[!INCLUDE fabric-se]](data-warehousing.md#sql-analytics-endpoint-of-the-lakehouse) or [[!INCLUDE fabric-dw]](data-warehousing.md#fabric-data-warehouse) via a T-SQL connection string. For more information, see Connectivity.
- Download SQL Server Management Studio (SSMS).
- Download and install both Visual Studio Code and the MSSQL extension.
Note
Review the T-SQL surface area in Fabric Data Warehouse for [!INCLUDE fabric-se] or [!INCLUDE fabric-dw] in [!INCLUDE product-name].
-
Open a New SQL query window.
:::image type="content" source="media/query-warehouse/new-sql-query.png" alt-text="Screenshot showing where to select New SQL query in the ribbon." lightbox="media/query-warehouse/new-sql-query.png":::
-
A new tab appears for you to write a SQL query.
:::image type="content" source="media/query-warehouse/sql-query-tab.png" alt-text="Screenshot of a new query tab in the SQL query editor the Fabric portal." lightbox="media/query-warehouse/sql-query-tab.png":::
-
Write a SQL query and run it.
:::image type="content" source="media/query-warehouse/write-sql-query.png" alt-text="Screenshot of a writing a SQL query." lightbox="media/query-warehouse/write-sql-query.png":::
-
Open a New visual query window.
:::image type="content" source="media/query-warehouse/new-visual-query.png" alt-text="Screenshot showing where to select New visual query in the ribbon." lightbox="media/query-warehouse/new-visual-query.png":::
-
A new tab appears for you to create a visual query. To add tables to the visual query, right-click on tables in the Explorer, or select their
...action menu, and select Insert to canvas. Or, you can drag and drop them into the visual query by selecting, holding, then dragging the tables from the Explorer. :::image type="content" source="media/query-warehouse/insert-into-canvas.png" alt-text="Screenshot of adding a table to the visual query. Select Insert to canvas." lightbox="media/query-warehouse/insert-into-canvas.png":::[!TIP] To drag and drop tables from the Explorer, select, hold, and then drag them into the visual query.
-
Join tables together using options in the Combine window. In the following screenshot, we join the
DateandWeathertables using an Inner join on the commonDateIDkey columns.:::image type="content" source="media/query-warehouse/merge.png" alt-text="Screenshot of the Merge window joining the Date and Trip tables in the visual query editor." lightbox="media/query-warehouse/merge.png":::
-
The result set join shows combined data. You can manipulate the query with other functions in the Visual query editor toolbar. You can save the resulting query as a new view or view the T-SQL as well.
You can write cross database queries to warehouses and databases in the current active workspace in [!INCLUDE product-name].
There are several ways you can write cross-database or cross-warehouse queries within the same [!INCLUDE product-name] workspace, in this section we explore examples. You can join tables or views to run cross-warehouse queries within current active workspace.
-
Add [[!INCLUDE fabric-se]](data-warehousing.md#sql-analytics-endpoint-of-the-lakehouse) or [[!INCLUDE fabric-dw]](data-warehousing.md#fabric-data-warehouse) from your current active workspace to object Explorer using + Warehouses action. When you select [[!INCLUDE fabric-se]](data-warehousing.md#sql-analytics-endpoint-of-the-lakehouse) or [[!INCLUDE fabric-dw]](data-warehousing.md#fabric-data-warehouse) from the dialog, it gets added into the object Explorer for referencing when writing a SQL query or creating Visual query.
:::image type="content" source="media/query-warehouse/add-warehouses.png" alt-text="Screenshot showing how to use add warehouses in object explorer." lightbox="media/query-warehouse/add-warehouses.png":::
-
You can reference the table from added databases using three-part naming. In the following example, use the three-part name to refer to
ContosoSalesTablein the added databaseContosoLakehouse.SELECT * FROM ContosoLakehouse.dbo.ContosoSalesTable AS Contoso INNER JOIN Affiliation ON Affiliation.AffiliationId = Contoso.RecordTypeID;
-
Using three-part naming to reference the databases/tables, you can join multiple databases.
SELECT * FROM ContosoLakehouse.dbo.ContosoSalesTable AS Contoso INNER JOIN My_lakehouse.dbo.Affiliation ON My_lakehouse.dbo.Affiliation.AffiliationId = Contoso.RecordTypeID;
-
For more efficient and longer queries, you can use aliases.
SELECT * FROM ContosoLakehouse.dbo.ContosoSalesTable AS Contoso INNER JOIN My_lakehouse.dbo.Affiliation as MyAffiliation ON MyAffiliation.AffiliationId = Contoso.RecordTypeID;
-
Using three-part naming to reference the database and tables, you can insert data from one database to another.
INSERT INTO ContosoWarehouse.dbo.Affiliation SELECT * FROM My_Lakehouse.dbo.Affiliation;
-
You can drag and drop tables from added databases to Visual query editor to create a cross-database query.
:::image type="content" source="media/query-warehouse/cross-warehouse-query-visual-query-editor.png" alt-text="Screenshot of a cross-database query in visual query editor." lightbox="media/query-warehouse/cross-warehouse-query-visual-query-editor.png":::
-
After opening your warehouse from the workspace, expand your database, schema, and tables folder in the object Explorer to see all tables listed.
-
Right-click on the table that you would like to query and select Select TOP 100 rows.
:::image type="content" source="media/query-warehouse/select-top-100-rows.png" alt-text="Screenshot showing where to select the Select Top 100 Rows option in the right-click menu." lightbox="media/query-warehouse/select-top-100-rows.png":::
-
Once the script is automatically generated, select the Run button to run the script and see the results.
You can query external data from the warehouse as well, including:
[!div class="nextstepaction"] Create reports on data warehousing in Microsoft Fabric