Microsoft Fabric SQL and Visual Query Editor for DP-600
Introduction
Use Microsoft Fabric SQL and the Visual Query Editor to explore Delta tables, join data and summarize results. This DP-600 lesson covers visual queries and reusable views, then uses T-SQL for grouped totals, ranking, and running sums. You will also learn when to use a warehouse or a lakehouse SQL analytics endpoint.
Learning objectives
- Build and save a query in the visual query editor, and know its limits.
- Write T-SQL to select, filter, sort, join and aggregate data.
- Use CTEs and window functions to answer ranking and running-total questions.
- Explain the role and the read-only nature of the SQL analytics endpoint of a lakehouse.
- Query across items in a workspace and pick the right query surface for the user.
1. Where SQL runs in Fabric
Fabric offers T-SQL on several items. Capabilities depend on the item and the endpoint you connect to.
| Item | T-SQL surface | Query table data | Write table data with T-SQL | Create a table with T-SQL |
|---|---|---|---|---|
| Warehouse | Native | Yes | Yes | Yes |
| Lakehouse | SQL analytics endpoint | Yes, for supported Delta tables | No | No. You can create views, supported functions and procedures |
| Mirrored database | SQL analytics endpoint | Yes, for mirrored tables | No | No. You can add supported query objects |
| SQL database in Fabric | Native database connection | Yes | Yes | Yes |
Key facts for the exam:
- The SQL analytics endpoint gives read-only T-SQL access to the Delta tables of a lakehouse. To change the data you use Spark (notebooks, Spark job definitions), dataflows or pipelines. Writing through the endpoint does not work for tables.
- Tables created or changed through Spark appear in the endpoint after an automatic metadata sync. A newly created table or column can be absent until sync finishes. SQL reads the registered Delta data from OneLake without a separate load into the endpoint.
- The endpoint exposes eligible registered tables, including Delta tables referenced by shortcuts under Tables. Plain files in the Files area are not registered SQL tables.
- Access to a lakehouse table depends on the endpoint’s identity mode. User identity mode evaluates OneLake table roles. Delegated mode uses SQL controls such as object permissions and RLS. See workspace access and OneLake security in Fabric.
2. The visual query editor
The Visual Query Editor uses a Power Query diagram to build queries in warehouses and supported SQL analytics endpoints, including mirrored databases. Add tables to the canvas and apply supported transformations. For a query that translates fully, inspect its T-SQL before saving or extending it.
Common operations include the following. The editor supports a subset of Power Query steps, so check whether your combination can be translated.
| Operation | Effect | SQL equivalent |
|---|---|---|
| Choose columns / Remove columns | Keeps only the needed columns | SELECT col1, col2 |
| Reduce rows (keep top rows, filter) | Keeps rows matching a condition or a number | WHERE, TOP |
| Sort rows | Orders rows | ORDER BY |
| Group by | Aggregates by one or more keys | GROUP BY with SUM, COUNT, AVG... |
| Merge queries | Joins two queries horizontally | JOIN (inner, left, right, full, anti) |
| Append queries | Stacks rows vertically | UNION ALL |
| Add custom column | Calculated column from an expression | A computed expression in SELECT |
| Remove duplicates | Distinct rows | DISTINCT |
| Transform (pivot, unpivot, replace values, data type) | Reshape or clean | PIVOT, UNPIVOT, CASE, CAST |
What you can do with the result:
- Save as view creates a reusable SQL object for a query with load enabled. Choose a schema where you can create views and confirm the generated SQL.
- Save as table persists query results via CTAS in an eligible warehouse and schema. This action requires permission to create a table on the target. The lakehouse SQL analytics endpoint still cannot write to lakehouse tables.
- View SQL shows the translation when supported. Enable load on the output query and expand the joined columns so the SQL reflects the result you intend to save.
- Supported results can be opened in Excel or visualized. Check the feature limits, for example when an ORDER BY clause is present.
The canvas runs read-only SELECT queries. Save as view and Save as table are separate actions. Use the SQL query editor for manual T-SQL, and use a Warehouse for supported DML.
Example. A sales manager at Contoso Outdoor wants revenue by product for 2026. She merges FactSales and DimProduct on ProductKey, expands the product name, filters OrderDate to the year and groups by ProductKey and ProductName. She uses Save as view to publish the product totals with permission from the warehouse owner. In the consuming report, she can sort and show the top ten products. Keeping ProductKey in the grouping avoids merging products with the same name.
3. The SQL query editor and other T-SQL surfaces
Besides the visual editor, Fabric provides:
- The SQL query editor in the portal: write T-SQL, run selected statements, save queries as personal or shared.
- SQL Server Management Studio and Visual Studio Code with the MSSQL extension, using the item’s SQL connection string and Microsoft Entra authentication. Azure Data Studio was retired on February 28, 2026.
- Notebooks with T-SQL cells (connect a T-SQL notebook to a supported SQL item) and PySpark cells with
spark.sqlfor the lakehouse. - Copilot features that draft T-SQL from a prompt, which you should always review.
Authentication uses Microsoft Entra ID. Cross-item queries are possible: from a warehouse you can reference a lakehouse or another warehouse of the same workspace with three-part names (SalesLakehouse.dbo.Orders), which lets one statement join accessible tables from both items without a separate copy. The caller needs permission on the referenced items and objects.
4. Selecting and filtering
The basic query shape and the order in which clauses bind matter for the exam. For this example, reason from FROM and JOIN to WHERE, then from the select list to sorting and row selection. This logical order does not dictate the physical execution plan.
SELECT TOP (20)
p.Category,
p.ProductName,
s.OrderDate,
s.SalesAmount
FROM dbo.FactSales AS s
JOIN dbo.DimProduct AS p ON p.ProductKey = s.ProductKey
WHERE s.OrderDate >= '2026-01-01'
AND s.OrderDate < '2027-01-01'
AND p.Category IN ('Bikes', 'Accessories')
AND s.SalesAmount BETWEEN 100 AND 5000
ORDER BY s.SalesAmount DESC, s.OrderID, s.OrderLineNumber;Useful predicates and patterns:
| Need | Pattern |
|---|---|
| Range of dates | OrderDate >= '2026-01-01' AND OrderDate < '2027-01-01' (half-open, avoids time-of-day bugs) |
| List of values | Category IN ('Bikes','Accessories') |
| Text search | ProductName LIKE 'Mountain%' |
| Missing value | Region IS NULL (never = NULL) |
| Conditional label | CASE WHEN SalesAmount > 1000 THEN 'Large' ELSE 'Small' END |
| Paging | ORDER BY ... OFFSET 40 ROWS FETCH NEXT 20 ROWS ONLY |
| Distinct values | SELECT DISTINCT Category |
TOP without ORDER BY returns an arbitrary set of rows; for a "top N" question, sort by the requested measure. The example also sorts by an order-line key to resolve ties. Use WITH TIES on the relevant sort expression if the business asks to include the boundary ties. Function calls on a filtered column (for example WHERE YEAR(OrderDate) = 2026) can prevent efficient data skipping; comparing the raw column to a range is the safer habit.
5. Aggregating data
Aggregates reduce rows to summary values: SUM, COUNT, COUNT(DISTINCT ...), AVG, MIN, MAX, plus statistical ones such as STDEV. Fabric Warehouse also offers APPROX_COUNT_DISTINCT, a fast estimate for very large tables when an exact count is not required.
SELECT d.CalendarYear,
d.MonthNumber,
c.Region,
SUM(s.SalesAmount) AS Revenue,
COUNT(DISTINCT s.OrderID) AS Orders,
AVG(s.SalesAmount) AS AvgLine
FROM dbo.FactSales s
JOIN dbo.DimDate d ON d.DateKey = s.OrderDateKey
JOIN dbo.DimCustomer c ON c.CustomerKey = s.CustomerKey
WHERE d.CalendarYear = 2026
GROUP BY d.CalendarYear, d.MonthNumber, c.Region
HAVING SUM(s.SalesAmount) > 50000
ORDER BY d.MonthNumber, Revenue DESC;Rules the exam likes to test:
- Columns used in a non-aggregated SELECT expression must be covered by the grouping expressions.
WHEREfilters rows before grouping and cannot reference aggregates;HAVINGfilters groups after aggregation.- Aggregates ignore NULLs, except
COUNT(*)which counts rows.COUNT(col)counts non-null values. - Column aliases defined in
SELECTcan be used inORDER BYbut not inWHEREorHAVING. GROUP BY ROLLUP,CUBEandGROUPING SETSexpress several grouping levels in one query. Fabric documents them for Warehouse and the SQL analytics endpoint. For subtotal rows, use GROUPING if you need to tell a rolled-up value from a source NULL.
SELECT Region, Category, SUM(SalesAmount) AS Revenue
FROM dbo.vSalesDetail
GROUP BY ROLLUP (Region, Category); -- adds regional subtotals and a grand total6. Joins, set operators and CTEs
Join types in T-SQL mirror the visual editor: INNER, LEFT, RIGHT, FULL, CROSS. "Anti" results are written with LEFT JOIN ... WHERE right.key IS NULL or NOT EXISTS. Prefer NOT EXISTS to NOT IN when the subquery column may contain NULLs, because a NULL can make the unmatched comparison evaluate to UNKNOWN.
Set operators combine results with the same column count and compatible types: UNION (distinct), UNION ALL (keeps duplicates), INTERSECT, EXCEPT.
A common table expression (CTE) names an intermediate result and makes long queries readable:
WITH MonthlyRevenue AS (
SELECT d.CalendarYear, d.MonthNumber, SUM(s.SalesAmount) AS Revenue
FROM dbo.FactSales s
JOIN dbo.DimDate d ON d.DateKey = s.OrderDateKey
GROUP BY d.CalendarYear, d.MonthNumber
)
SELECT *
FROM MonthlyRevenue
WHERE Revenue > 1000000;7. Window functions
A window function computes a value for each row over a related set of rows without collapsing them (unlike GROUP BY). The OVER clause can define PARTITION BY (the groups), ORDER BY (the order) and, for functions that accept it, a frame (ROWS BETWEEN ...).
| Function | Use |
|---|---|
ROW_NUMBER() |
Unique sequence per partition (deduplication, top-N per group) |
RANK() / DENSE_RANK() |
Ranking with ties; RANK leaves gaps, DENSE_RANK does not |
LAG() / LEAD() |
Previous or next row value (period-over-period) |
SUM() OVER (...) |
Running totals and moving sums |
NTILE(n) |
Quartiles, deciles |
FIRST_VALUE() / LAST_VALUE() |
First or last value in the frame |
SELECT Region,
OrderMonth,
Revenue,
SUM(Revenue) OVER (PARTITION BY Region ORDER BY OrderMonth
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS RunningRevenue,
LAG(Revenue) OVER (PARTITION BY Region ORDER BY OrderMonth) AS PrevMonth,
RANK() OVER (PARTITION BY OrderMonth ORDER BY Revenue DESC) AS RankInMonth
FROM dbo.vMonthlyRevenue;The window calculation happens after WHERE and HAVING. The portable T-SQL pattern is to compute the value in a CTE or subquery and filter it outside. Microsoft also documents QUALIFY in the Fabric T-SQL extensions. Check feature availability before relying on it.
Worked example: best product per region
Statement. Fabrikam sells in five regions. The analyst needs, for each region, the product with the highest revenue in 2026, and a tie must return all tied products. The warehouse view dbo.vRegionProductRevenue(Region, ProductName, Revenue) already summarizes 2026 sales to one row per region and product.
Reasoning. (1) Aggregation alone gives the max revenue per region, but not the product name; joining back to it works but is clumsy. (2) A ranking per region answers directly: partition by Region, order by Revenue descending. (3) Because ties must all be returned, RANK() or DENSE_RANK() gives each tied product rank 1; ROW_NUMBER() would pick one arbitrary product. (4) Put the ranking in a CTE to filter it with an outer WHERE.
Solution.
WITH ranked AS (
SELECT Region, ProductName, Revenue,
RANK() OVER (PARTITION BY Region ORDER BY Revenue DESC) AS rnk
FROM dbo.vRegionProductRevenue
)
SELECT Region, ProductName, Revenue
FROM ranked
WHERE rnk = 1;Why the other choices are worse. TOP 1 returns one row for the whole table, not one per region. ROW_NUMBER() hides ties. GROUP BY Region with MAX(Revenue) loses the product name. A subquery with WHERE Revenue = (SELECT MAX(Revenue) ...) without correlation compares to the global maximum only.
8. Reading the lakehouse through the SQL analytics endpoint
The endpoint is created automatically with the lakehouse (and with a mirrored database). Think of it as a read-only SQL window onto Delta tables.
What it supports:
- Queries over Delta tables, including cross-item queries with three-part names.
- Creating supported SQL query objects, including views, inline table-valued functions and stored procedures. See Fabric views, functions and stored procedures for examples and their write restrictions.
- The visual query editor, the SQL query editor, external clients and Power BI semantic models in Direct Lake or DirectQuery mode.
What it does not support: INSERT, UPDATE, DELETE, MERGE and CREATE TABLE on the lakehouse tables. If the question says "the team needs to update rows with T-SQL", the answer is a warehouse (or SQL database), not the endpoint.
Two behaviors that appear in scenarios:
- Metadata sync delay: new tables or schema changes written by Spark show up after sync. If a new table is missing, check that it was registered as a supported table and that your identity has access. Use Refresh in the endpoint Explorer when you need an on-demand metadata sync. The sync does not grant permissions or turn raw files into tables.
- Unsupported table formats: folders of plain Parquet or CSV files are not exposed as tables.
9. Comparing the query tools
| Question in the scenario | Best surface |
|---|---|
| Analyst with no SQL skills wants a quick aggregation and a reusable result | Visual query editor, then Save as view |
| Developer needs window functions, CTEs and complex aggregation | SQL query editor |
| Need to update data with T-SQL | Warehouse (not the lakehouse endpoint) |
| Join lakehouse and warehouse data in a single statement | Three-part names from a warehouse query |
| Explore raw files not yet in tables | Notebook, or load into a Delta table first |
| Large exploratory counts where approximation is acceptable | APPROX_COUNT_DISTINCT |
| Time-series logs in an eventhouse | KQL (next lesson) |
Common pitfalls
- Writing
WHERE Column = NULLinstead ofIS NULL. - Filtering with an aggregate in
WHEREinstead ofHAVING. - Using
TOPwithoutORDER BYand trusting the result. - Using
ROW_NUMBER()when ties matter, orRANK()when gaps are not wanted. - Using
NOT INagainst a nullable column. - Expecting to run
UPDATEthrough a lakehouse SQL analytics endpoint. - Forgetting the metadata sync delay when a new Spark table is not visible yet.
- Joining on columns of different data types and silently converting every row.
- Believing the visual query editor can write data or run procedural logic.
Exam tip: when a scenario states that the user "does not write code" and needs a reusable dataset, think visual query editor plus Save as view. When it needs a ranking per group, think RANK/DENSE_RANK/ROW_NUMBER in a CTE. When it mentions modifying data with T-SQL, check whether the target is a warehouse or a lakehouse endpoint.
Mini case study
Adventure Works Rentals stores rental data in a lakehouse RentalsLH (loaded nightly by Spark) and curated dimensions in a warehouse RentalsDW, both in the same workspace. The finance team (T-SQL users) asks for a monthly report: revenue by branch, running year-to-date revenue, and the best three bikes per branch. A marketing analyst without SQL skills wants a list of customers with no rental in the last 12 months. Finance also asks to correct 200 mistyped branch codes in the lakehouse table with an UPDATE statement.
Proposed solution.
- Finance uses the SQL query editor on the warehouse. A CTE aggregates revenue by branch and month from
RentalsLH.dbo.Rentals(three-part name), joined toRentalsDW.dbo.DimBranch. To reset the total each January, useSUM(Revenue) OVER (PARTITION BY Branch, CalendarYear ORDER BY MonthNumber ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW). The monthly CTE has one row per branch, year and month. - In a separate query, aggregate revenue to one row per branch and bike over the reporting period. Use DENSE_RANK and filter to ranks 1–3 if the report should show the three highest distinct revenue levels with ties. For exactly three bikes where available, use ROW_NUMBER and a stable bike key to break ties.
- The marketing analyst uses the visual query editor: filter the rental input to the last 12 months, then use a left anti merge from
DimCustomerto that input and Save as view for her Power BI report. - The
UPDATEcannot run on the lakehouse SQL analytics endpoint. The correction is done in a notebook with a DeltaUPDATE/MERGEstatement (or fixed upstream and reloaded); the endpoint then shows the corrected values after sync.
Commentary. Each need matched the surface with the right capability. The only trap was the write: the endpoint is read-only, so the fix belongs in Spark, or the table moves to a warehouse if T-SQL writes are a permanent requirement.
Key terms
- Visual query editor: no-code query builder that generates T-SQL.
- SQL analytics endpoint: read-only T-SQL access to lakehouse (or mirrored) Delta tables.
- CTE: named intermediate result defined with
WITH. - Window function: calculation over a set of rows related to the current row, defined with
OVER. - HAVING: filter applied to groups after aggregation.
- Three-part name:
item.schema.tablesyntax for cross-item queries. - Metadata sync: process that refreshes endpoint table definitions after changes in the lakehouse.
- ROLLUP / CUBE / GROUPING SETS: grouping extensions producing subtotals.
Summary checklist
- I can build, save as a view and inspect the SQL of a visual query.
- I can explain the difference between a read-only visual query, saving a query result into a Warehouse table, and the lakehouse endpoint’s table write restrictions.
- I can write SELECT, WHERE, GROUP BY, HAVING and ORDER BY in the correct logical order.
- I can pick RANK, DENSE_RANK or ROW_NUMBER depending on tie handling, and filter them through a CTE.
- I can write running totals and period comparisons with window functions.
- I know when a warehouse, not a lakehouse endpoint, is required.
Official sources
- Study guide for Exam DP-600: https://learn.microsoft.com/en-us/credentials/certifications/resources/study-guides/dp-600 (opens in a new tab)
- Query using the visual query editor: https://learn.microsoft.com/en-us/fabric/data-warehouse/visual-query-editor (opens in a new tab)
- Query using the SQL query editor: https://learn.microsoft.com/en-us/fabric/data-warehouse/sql-query-editor (opens in a new tab)
- SQL analytics endpoint for a lakehouse: https://learn.microsoft.com/en-us/fabric/data-engineering/lakehouse-sql-analytics-endpoint (opens in a new tab)
- Endpoint metadata synchronization: https://learn.microsoft.com/en-us/fabric/data-engineering/sql-analytics-endpoint-metadata-sync (opens in a new tab)
- Fabric GROUP BY syntax: https://learn.microsoft.com/en-us/sql/t-sql/queries/select-group-by-transact-sql?view=fabric (opens in a new tab)
- Fabric QUALIFY clause: https://learn.microsoft.com/en-us/sql/t-sql/queries/select-qualify-clause-transact-sql?preserve-view=true&view=fabric (opens in a new tab)
- T-SQL surface area of the Fabric Data Warehouse: https://learn.microsoft.com/en-us/fabric/data-warehouse/tsql-surface-area (opens in a new tab)
