SQL Standard

SQL Count Distinct Values

In SQL, the count function is used to determine the number of records that matches a specified condition from a database table.

However, running the count function will return all records, including duplicated rows. We can solve duplicate records by using the DISTINCT clause in SQL. This clause filters only the unique records from a count function result set.

Let us discuss using this function and the distinct clause to filter for unique result sets.

SQL Count

The count function returns the number of rows matching a condition. The function syntax is as shown:

COUNT(*)
COUNT( [ALL|DISTINCT] expression )

The code above shows the function syntax as expressed in Standard SQL. Various database engines may have different implementations of the function.

But different database vendors may have different ways of applying COUNT() function.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list