I have to make a query inside another query in order to find entries in a table that have characteristics but not others. The characteristics are derived from a connection to another table.
Basically, I have a plans table and a parcels table. I need to find the plans that relate to both (building strata, bareland strata, common ownership) and (road, subdivision, park, interest). These plans should contain entries in one list, but not both.
Here is what I have so far.
SELECT *
FROM parcelfabric_plans
WHERE
(name in
(select pl.name from parcelfabric_parcels p inner join
parcelfabric_plans pl on p.planid = pl.objectid
WHERE
p.parcelclass IN ( 'ROAD', 'SUBDIVISION', 'PARK', 'INTEREST')))
This is the first query, which gets all the plans that have parcels related to them in this list. How do I query this selection to get plans within this selection that are also related to the second list (subdivisions, interests, roads, parks)?
This query returns 268983 results of plans. Of these results, I would like to be able to query them and get the number of plans that are also related to subdivisions, interests, roads, parks.