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.
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!