==Joining geo with portcoipomas==
Check the portcoipomas table first. Undisclosed Companies may have slipped through so you might have to rerun the joins against the companybase1 table selecting the appropriate flags. You will match portcoipomas with the geo data using coname, city, year so you will need to strip the year from the datefirstinv. Use the EXTRACT(YEAR FROM datefirstinv) command.I broke these into separate tables: CREATE TABLE portcoipomalocationexclude AS SELECT *, EXTRACT(YEAR FROM datefirstinv) AS datefirstyear FROM portcoipomalocation AS portco WHERE NOT EXISTS(SELECT * FROM excludeipomadupes as exclude WHERE (portco.coname = exclude.coname AND portco.statecode = exclude.statecode AND portco.datefirstinv = exclude.datefirstinv AND exclude.excludeflag = 1)); CREATE TABLE companybasegeo AS SELECT portco.*, geo.lattitude, geo.longitude, geo.noaddress FROM portcoipomalocationexclude as portco LEFT JOIN geo ON (portco.coname = geo.coname AND portco.city = geo.city AND portco.datefirstyear = geo.startyear);