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

How to Count Unique Email Addresses in a Table?

DDD
Release: 2024-10-31 21:54:28
Original
743 people have browsed it

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template