Full Version: Multiple column search for "in" statement
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
buttons
I've been stuck on this SQL query for a while.

I have two copies of the same table. One is before some rows have been deleted the other is after. That would be simple enough but I have multiple key fields. I would like to have a command that would find the lines that are missing in the new copy.

Something like:

CODE
  select ID from TABLE_COPY2 where ID not in (select ID from TABLE_COPY1)


Except adapted for a two columns search:

CODE
select ID, ID2 from TABLE_COPY2 where (ID, ID2) not in (select ID, ID2 fril TABLE_COPY2)


This syntax does not work but it's that logic I would like to use.

Any ideas on how I could do this (with or without my preferred logic!)?

Thanks

B.
niesz
Have you tried using the Unmatched Query Wizard?
buttons
No. Where can I find that?
niesz
Queries Tab: New


Edited by: niesz on Thu Jul 27 10:23:52 EDT 2006.
buttons
This will only work for one field. The wizard wont let me chose more.

Any other ideas?
niesz
You could try something like:

SELECT Table1.ID, Table1.MyField1, Table1.MyField2
FROM Table1 LEFT JOIN Table2 ON (Table1.MyField2 = Table2.MyField2) AND (Table1.MyField1 = Table2.MyField1)
WHERE (((Table2.MyField1) Is Null) AND ((Table2.MyField2) Is Null));

This example uses 2 fields in common.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.