A Shot of SQLEspresso

SQL Blogs by Monica Morehouse (Rathbun)

  • Home
  • Session Downloads
  • Event Calendar
  • PASS
    • Hampton Roads SQL User Group
    • SQL Saturday
    • PASS WIT VC
  • DCAC
  • Contact Me
    • Disclaimer
  • Home
  • Session Downloads
  • Event Calendar
  • PASS
    • Hampton Roads SQL User Group
    • SQL Saturday
    • PASS WIT VC
  • DCAC
  • Contact Me
    • Disclaimer

No Widgets found in the Sidebar Alt!

  • New SQL Version

    Approximate COUNT DISTINCT

    January 3, 2019 /

    We all have written queries that use COUNT DISTINCT to get the unique number of non-NULL values from a table. This process can generate a noticeable performance hit especially for larger tables with millions of rows. Many times, there is no way around this. To help mitigate this overhead SQL Server 2019 introduces us to approximating the distinct count with the new APPROX_COUNT_DISTINCT function. The function approximates the count within a 2% precision to the actual answer at a fraction of the time. Let’s see this in action. In this example, I am using the AdventureworksDW2016CTP3 sample database which you can download here.  SET STATISTICS IO ON SELECT COUNT(DISTINCT([SalesOrderNumber])) as DISTINCTCOUNT…

    Read More
    Monica Morehouse (Rathbun)

    Related Posts

    Memory Optimized Tables in SQL Server

    January 8, 2020

    Back to Basics: Why not parameterize?

    December 23, 2015

    Scooby-Doo and the Mystery of Cloud Costs (Let’s have some fun!) – Scooby Dooing Episode 1

    August 25, 2025

About Me

Monica Morehouse (Rathbun)

Microsoft MVP, Performancing Tuning Expert, Leader Hampton Roads SQL Server User Group, Read More…

Consulting

Sessions List

Favorite Tidbits

  • Reminder to Developers

Topic Categories

  • Azure
  • Back to Basics
  • Configurations
  • Data Masking
  • DevOps
  • Encryption
  • Idera Ace
  • Important Links
  • Indexes
  • Lone DBA
  • Misc
  • MVP
  • New SQL Version
  • Performance Tuning
  • Posts with Scripts
  • Problems & Solutions
  • Quick and Dirty
  • Security
  • Speaking
  • SQL Family
  • SQLSaturday
  • SSRS
  • Summit
  • Training
  • TSQL Tuesday
  • Uncategorized

Top Posts & Pages

  • What’s a Key Lookup?
    What’s a Key Lookup?
  • Why DBAs Still Need to Know the Foundations of SQL Server
    Why DBAs Still Need to Know the Foundations of SQL Server
  • How to get started with Always Encrypted for Beginners Part 1
    How to get started with Always Encrypted for Beginners Part 1
  • Filtered Index Basics
    Filtered Index Basics
  • Resizing Tempdb (When TEMPDB Wont Shrink)
    Resizing Tempdb (When TEMPDB Wont Shrink)
  • System-Versioned Temporal Tables
    System-Versioned Temporal Tables
  • Please Don’t Do This! Default Index Fill Factor
    Please Don’t Do This! Default Index Fill Factor
  • Understanding Columnstore Indexes in SQL Server Part 2
    Understanding Columnstore Indexes in SQL Server Part 2
  • Just Check ALL the Boxes - SQL Server Installs
    Just Check ALL the Boxes - SQL Server Installs
  • What is Azure SQL Database Serverless?
    What is Azure SQL Database Serverless?
Graceful Pro Theme by Optima Themes - 2026 ©
 

Loading Comments...