Why in order to count the number of duplicate values in a field, you can write:
SELECT *, COUNT(phone) FROM registered_phones GROUP BY phone HAVING COUNT(1)>1; And in order to calculate the number of non-repeating values, you need to write:
SELECT COUNT(*) FROM ( SELECT DISTINCT phone FROM registered_phones ) t; and you can not write:
SELECT DISTINCT phone, COUNT(phone) FROM registered_phones; This last query will return an invalid value. What is the reason for this?
UPD:
I also noticed that after all, you can return the correct number of non-repeating values by the following query:
SELECT DISTINCT phone, COUNT(DISTINCT phone) FROM registered_phones;