Reputation: 2597
I am running a program that stores a phone number each time that phone number calls by inserting a entry into a sqlite table called numberlogger with the phone number that called and a primary key.
I now would like to get a Count of how many individual phone numbers are in that table, meaning that even if a phone number called 5000 times, it should still only count as plus one in the count since its the same phone number.
I have tried this
SELECT COUNT(*)
FROM numberlogger;
but it adds plus one to each entry including from the same phone number, so its not what I would like.
I then tried a nested query with a group statement
SELECT Count(*)
FROM numberlogger
WHERE EXISTS (SELECT *
FROM numberlogger
GROUP BY phonenumber);
but it still counted duplicates.
Any idea of what query I can use To get a count of individual phone numbers, not counting duplicates?
Upvotes: 0
Views: 679
Reputation: 93724
Use Distinct
inside Count
aggregate to avoid counting duplicate values. Try this
SELECT COUNT(distinct phonenumber) FROM numberlogger;
It will count a phone number only once even if the same phone number called 5000 times
Upvotes: 2