SQL Tips
3 min read

SQL GROUP BY Multiple Columns: Think in Result Grain

Learn how SQL Server groups unique column combinations using a practical Region + SalesChannel revenue example.

D

Dan Griffin

Senior Data Analyst · February 10, 2026

SQL GROUP BY Multiple Columns: Think in Result Grain
In this article: SQL Server can GROUP BY multiple columns, but the important concept is understanding the grain of the result. This example shows how grouping by Region and SalesChannel produces one row per unique combination, how adding grouping columns changes the level of detail, and how NULL values behave within grouped results.

A sales manager asks:

"Show me revenue and order count by region and sales channel."

This sounds like a simple GROUP BY question.

But the important SQL question is not:

"Can I GROUP BY multiple columns?"

Yes, you can.


The better question is:

"What does one row in my result represent?"

Suppose we have this small order dataset:


DECLARE @OrderSales TABLE
(
    OrderId      INT,
    Region       VARCHAR(20),
    SalesChannel VARCHAR(20) NULL,
    Revenue      DECIMAL(10, 2)
);

INSERT INTO @OrderSales
(
    OrderId,
    Region,
    SalesChannel,
    Revenue
)
VALUES
    (101, 'North', 'Online',  120.00),
    (102, 'North', 'Online',  180.00),
    (103, 'North', 'Partner', 250.00),
    (104, 'South', 'Online',  300.00),
    (105, 'South', 'Retail',  150.00),
    (106, 'South', 'Retail',  200.00),
    (107, 'North', NULL,       90.00),
    (108, 'North', NULL,       60.00);


If the business wants one row per region, we could group only by Region.

But the requirement is more detailed:

One row per Region + SalesChannel combination.


SELECT
    Region,
    SalesChannel,
    COUNT(*) AS OrderCount,
    SUM(Revenue) AS TotalRevenue
FROM @OrderSales
GROUP BY
    Region,
    SalesChannel
ORDER BY
    Region,
    SalesChannel;


The result is:

Region   SalesChannel   OrderCount   TotalRevenue
-------  -------------  -----------  ------------
North    NULL            2            150.00
North    Online          2            300.00
North    Partner         1            250.00
South    Online          1            300.00
South    Retail          2            350.00


Keep Reading

Get free access to the full article

Join data professionals reading weekly SQL tips, career guides, and interview prep — completely free.

No credit card. No spam. Unsubscribe anytime.

Recommended Reading