Fixing state, country missing with other records
I created a Select to identify the records with missing state and country. Then I upped it to find a valid substitute from another record. Unfortunately some cities are in more than one state and BOTH city state combos are showing up in my select. I tried a HAVING clause but I wasn't allowed to use it there in either place. [HAVING distinct STATE = 1].
My data is collected from Aol Instant Messenger. Some of the fields are name, address, city, state, country, nickname, and other items. There is NO data checking on their part, so the data is really messy. I have to ignore many records because the fields contain worthless information. I created a table, STATES containing state or province name and their abbreviation for US and Canada. I use that to cut down on the junky words found in the STATE field.
I am now working on my 9i CERT, and discovered long ago that just doing work in a database gets the learning juices flowing a lot faster. I study a while then when inspired with a complex challenge, I go for it and learn a bunch. Then resume the study.
1. How can I modify this select so that the dual stated cities are not included ?
2. Then I want to update the records. I see I have a nested select and don't quite see how to translate this action into an update yet, are you able to make some suggestions?
Here is the updt.sql file contents that I have so far.
SET LINESIZE 160;
SET PAUSE ON;
select A.FNAM, A.LNAM, A.CITY, B.STATE, B.CNTRY, A.SNAM, A.STATE
from AIM A, (SELECT DISTINCT STATE, CNTRY, CITY FROM AIM
WHERE STATE IS NOT NULL
AND CNTRY IS NOT NULL
AND CITY IS NOT NULL
AND STATE IN (SELECT ST FROM STATES WHERE ST=UPPER(STATE))
--HAVING COUNT(DISTINCT STATE) = 1
WHERE A.CITY = B.CITY
AND (A.STATE IS NULL AND A.CNTRY IS NULL)
AND A.CITY IS NOT NULL
--AND COUNT(B.STATE) = 1;
--GROUP BY STATE, CNTRY DISTINCT