
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Get the count of unique phone numbers from a column with phone numbers declared as BIGINT type in MySQL
For this, you can use COUNT() along with DISTINCT. The COUNT() method is to count the records. However, the DISTINCT returns distinct records, whereas COUNT() method counts those unique records. Let us first create a table −
mysql> create table DemoTable ( PhoneNumber bigint ); Query OK, 0 rows affected (1.29 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(8567789898); Query OK, 1 row affected (0.94 sec) mysql> insert into DemoTable values(8567789898); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values(9876564534); Query OK, 1 row affected (0.43 sec) mysql> insert into DemoTable values(9087896545); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values(7656456589); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(9876564534); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(9087896545); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+ | PhoneNumber | +-------------+ | 8567789898 | | 8567789898 | | 9876564534 | | 9087896545 | | 7656456589 | | 9876564534 | | 9087896545 | +-------------+ 7 rows in set (0.00 sec)
Following is the query to count unique phone numbers from a column with phone numbers −
mysql> select count(distinct PhoneNumber) AS UniquePhoneNumber from DemoTable;
This will produce the following output −
+-------------------+ | UniquePhoneNumber | +-------------------+ | 4 | +-------------------+ 1 row in set (0.00 sec)
- Related Articles
- How to set country code to column values with phone numbers in MySQL?
- Get count of zeros for columns values declared with INT type in MySQL
- C++ Program to find length of country code from phone numbers
- Get the count of only unique rows in a MySQL column?
- Count Numbers with Unique Digits in C++
- How to extract the area codes from a phone number with MySQL?
- Find what numbers were pressed to get the word (opposite of phone number digit problem) in JavaScript
- How to Create Phone numbers and Contacts List in ReactJS?
- MySQL query to fetch column length declared with BLOB type
- MySQL to get only the floating-point numbers from a list of values in a column
- How to get phone number from content provider in android?
- MongoDB query to return only specific fields (phone numbers) in the form of an array?
- How to obtain the phone number of the android phone programmatically?
- How to obtain the phone number of the iOS phone programmatically?
- How to get phone number in android?

Advertisements