How to Filter Records with Aggregate Function Count in SQL
Let's look at a few examples of how this function can be used. Suppose you have a table called users with the following data:
If you wanted to count the number of distinct names in this table, you would use the following query:
This query would return the result 3, since there are three distinct names in the table (John, Jane, and Bob).
The COUNT(DISTINCT) function is supported by most major databases, including MySQL, PostgreSQL, and SQL Server. However, the syntax may vary slightly depending on the database you are using. For more information, check out the documentation for your particular database.