T-SQL on Microsoft Fabric - Episode 1: Mastering Data Retrieval with SELECT, WHERE, and ORDER BY
Learning Goals
In this lesson, you will learn how to:
- Read data from tables using
SELECT - Filter rows with
WHERE - Sort query results with
ORDER BY - Get familiar with standard T-SQL syntax
- Practice directly in Microsoft Fabric Warehouse
1. Understanding Database and Schema
In Fabric Warehouse, objects are commonly organized like this:
Warehouse
|
|-- sales
| |-- Customers
| |-- Orders
|
|-- hr
| |-- Employees
|
|-- finance
|-- Transactions
Schemas help you:
- Group related tables
- Manage permissions
- Organize large systems more effectively
2. Create a Schema
Create a schema for the sales dataset:
CREATE SCHEMA sales;
Check existing schemas:
SELECT *
FROM sys.schemas;
3. Create Tables
Create the Customers table:
CREATE TABLE sales.Customers
(
CustomerID INT,
CustomerName VARCHAR(100),
City VARCHAR(50),
Country VARCHAR(50)
);
Create the Orders table:
CREATE TABLE sales.Orders
(
OrderID INT,
CustomerID INT,
OrderDate DATE,
Amount DECIMAL(10,2)
);
4. Insert Sample Data
Customers
INSERT INTO sales.Customers
VALUES
(1, 'John Smith', 'New York', 'USA'),
(2, 'Emma Brown', 'Chicago', 'USA'),
(3, 'David Wilson', 'London', 'UK'),
(4, 'Sophia Taylor', 'Manchester', 'UK'),
(5, 'Michael Lee', 'Singapore', 'Singapore');
Orders
INSERT INTO sales.Orders
VALUES
(101, 1, '2026-01-10', 1200.00),
(102, 1, '2026-01-15', 800.00),
(103, 2, '2026-01-20', 2500.00),
(104, 3, '2026-02-01', 500.00),
(105, 5, '2026-02-05', 3200.00);
5. SELECT
Get all columns:
SELECT *
FROM sales.Customers;
Get specific columns:
SELECT CustomerName,
Country
FROM sales.Customers;
6. Alias
Rename columns in the output:
SELECT CustomerName AS Customer,
Country AS Nation
FROM sales.Customers;
7. WHERE
Filter rows using conditions.
Customers in the USA:
SELECT *
FROM sales.Customers
WHERE Country = 'USA';
Orders greater than 1000:
SELECT *
FROM sales.Orders
WHERE Amount > 1000;
Orders between 500 and 2000:
SELECT *
FROM sales.Orders
WHERE Amount BETWEEN 500 AND 2000;
Multiple conditions:
SELECT *
FROM sales.Customers
WHERE Country = 'UK'
AND City = 'London';
Use IN:
SELECT *
FROM sales.Customers
WHERE Country IN ('USA', 'UK');
8. DISTINCT
Return unique values:
SELECT DISTINCT Country
FROM sales.Customers;
9. ORDER BY
Sort query results.
Ascending order:
SELECT *
FROM sales.Orders
ORDER BY Amount;
Descending order:
SELECT *
FROM sales.Orders
ORDER BY Amount DESC;
Sort by multiple columns:
SELECT *
FROM sales.Customers
ORDER BY Country,
CustomerName;
10. TOP
Return the first N rows.
Top 3 orders:
SELECT TOP 3 *
FROM sales.Orders;
Top 3 highest-value orders:
SELECT TOP 3 *
FROM sales.Orders
ORDER BY Amount DESC;
11. Combining Clauses in a Real Query
Find the top 2 highest orders from customers in the USA:
SELECT TOP 2
c.CustomerName,
o.Amount
FROM sales.Customers c
JOIN sales.Orders o
ON c.CustomerID = o.CustomerID
WHERE c.Country = 'USA'
ORDER BY o.Amount DESC;
References
- Microsoft Fabric Documentation - Data Warehouse in Microsoft Fabric: https://learn.microsoft.com/fabric/data-warehouse/



















Top comments (0)