I would like to do something similar, but am running into problems.
I have buildings (BLDG) in tables BLDG_GEO and BLDG_BIO /*using the same
name for table and field can be confusing*/
I also have cities (CITY) in the same tables.
Occasionally there will be BLDG with the same name, but different cities.
I want just the entries in BLDG_BIO that don't already appear in BLDG_BIO
I tried
SELECT *
FROM BLDG_BIO
WHERE "BLDG_BIO.BLDG" <> "BLDG_GEO.BLDG" AND "BLDG_BIO.CITY" <>
"BLDG_GEO.CITY"
but all I get is everything from BLDG_BIO
what am I missing?
or am I off the mark completely?
Well, the text strings "BLDG_BIO.BLDG" and "BLDG_GEO.BLDG" are never going to
be equal - and that's what you're comparing, not the contents of those fields!
What you need is an "unmatched query" on the two tables. A "frustrated outer
join" is the correct approach here:
SELECT BLDG_BIO.*
FROM BLDG_BIO LEFT JOIN BLDG_GEO
ON BLDG_BIO.BLDG = BLDG_GEO.BLDG
AND BLDG_BIO.CITY = BLDG_GEO.CITY
WHERE BLDG_GEO.BLDG IS NULL;
This rather counterintuitive query joins all records in BLDG_BIO to the
corresponding record in BLDG_GEO, joining by BLDG and CITY; if there is no
such matching record, the LEFT JOIN gives NULL values from BLDG_GEO. The WHERE
criterion selects just those records which don't have a match.