How to do intersect and except sql operators in access?

G

Guest

There is a union operator to find items in either of 2 sets. Is there a way
to find items that are in both sets and another to find items in one set but
not in the other?

A union B contains all rows from A plus all rows from B (with no duplicates)

A intersect B would contain only rows that are in both tables A and B

A except B would contain only rows that are in A but not in B
 
J

John Vinson

There is a union operator to find items in either of 2 sets. Is there a way
to find items that are in both sets and another to find items in one set but
not in the other?

A union B contains all rows from A plus all rows from B (with no duplicates)

A intersect B would contain only rows that are in both tables A and B

A simple JOIN will accomplish this.
A except B would contain only rows that are in A but not in B

Use a "frustrated outer join" -

SELECT A.*
FROM [A] LEFT JOIN
ON [A].[fieldname] = B.[fieldname]
WHERE .[fieldname] IS NULL;

John W. Vinson[MVP]
 
P

PC Datasheet

To find items that are in both sets, include both A and B in a query and
join A to B on the field you want in both sets.

To find items in one set but not in the other, open to the database window
and click on the queries tab. Click on new, select the unmatched query
option and follow the directions.
 
G

Guest

Thanks,

I missed the unmatched query builder, but already came up with this...

SELECT AllStreets.StreetCity INTO NewStreets
FROM AllStreets
WHERE (((AllStreets.StreetCity) Not In (select StreetCity from
MarkedStreets)));

which may not be the best performer.

Other SQL (IBM's DB2) engines support UNION, INTERSECT and EXCEPT to do the
SET operations. They are missing from Access.
 
P

PC Datasheet

Access supports union queries. For the other two, Access just uses different
names.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ADO Minus/Intersect? 3
query - express builder 9
Except operator in Access 2003 1
SUM - IF - AND 7
Incorrect Record Count in Union 6
returning all rows 4
Intersect and Union 2
Emulate XOR in Access 5

Top