Home  >  Article  >  Database  >  How to Count Unique Email Addresses in a Table?

How to Count Unique Email Addresses in a Table?

DDD
DDDOriginal
2024-10-31 21:54:28650browse

How to Count Unique Email Addresses in a Table?

Counting Distinct Values

When working with a dataset with multiple columns, it's often necessary to determine the number of unique values within a specific column. This question arises when trying to count the number of unique emails in a table with columns orderNumber, name, and email.

While SELECT count(email) FROM orders provides the total count of all emails, it doesn't eliminate duplicates. To count only the unique email values, DISTINCT must be used.

Solution: Using DISTINCT

The correct query to count unique email values is:

<code class="sql">SELECT count(DISTINCT(email)) FROM orders</code>

The DISTINCT keyword applied to the email column ensures that only one occurrence of each unique email address is included in the count. This eliminates any duplicate emails and produces the desired unique count.

The above is the detailed content of How to Count Unique Email Addresses in a Table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn