I wish to select data from a table if, and only if, the unique mobile numbers are equal to the total number of rows in a table (i.e. we dont have two different people with the same mobile number, and/or we don't have a row with null values in the mobile number column), where there is a specific area code, e.g. 4817.
At the moment, I have the query bellow (which does not work with the AND constraint). Does anyone have any tips on how to do this?
SELECT
MOB_NUM AS MOBILE_NUMBER,
NAME AS NAME,
AREA_CODE AS AREA_CODE
FROM DB_PHONEBOOK DBP
WHERE DBP.AREA_CODE = 4817
AND (COUNT(DISTINCT DBP.MOB_NUM ) = COUNT(DBP.MOB_NUM))