bellegigi
asked on
Exclude Records in a Table from a query
Hi. Does anyone know how to exclude records in a query from another query?
i.e. - I have a query called qryGetActiveServiceSupport Fee and I have a query called
qryActiveAssociatesIndivid ualsFundCo rps. I want to create a new query that has all of the records in the latter, without those in the first.
Help!
Thanks!
i.e. - I have a query called qryGetActiveServiceSupport
qryActiveAssociatesIndivid
Help!
Thanks!
When you create a new query, select the option "Find Unmatched Query Wizard". This should give you exactly what you need....painlessly.
Supposing ID is the key field of both queries, I would write something like:
select id, f1, f1 from query1
where id not in (select id from query2)
This is rather slow, but it works.
select id, f1, f1 from query1
where id not in (select id from query2)
This is rather slow, but it works.
Charityg,
The wizard can be "painless", but won't support multiple outer-joins. Learning it from the editor will enable you to see the direction (LEFT or RIGHT) by an arrow and doesn't limit you to do it for just two tables.
I find that easier and more flexible as the "text" version of the wizard....
Nic;o)
The wizard can be "painless", but won't support multiple outer-joins. Learning it from the editor will enable you to see the direction (LEFT or RIGHT) by an arrow and doesn't limit you to do it for just two tables.
I find that easier and more flexible as the "text" version of the wizard....
Nic;o)
ASKER
I don't want the end result to include any records in the second query. Doesn't the first answer here leave it to where it will include the records if they match? I don't want to include them at all. I want them taken out of the first query. Thanks!
Check my comment:
>>>Now place the keyfield of the qryGetActiveServiceSupport Fee and test for "Is Null" (without quotes!).
>>> Thus only non-matching rows will appear.
Nic;o)
>>>Now place the keyfield of the qryGetActiveServiceSupport
>>> Thus only non-matching rows will appear.
Nic;o)
ASKER
So, that will keep out everything in the second query? The numbers aren't matching up... that's why I am confused.
Just check with a test on a small subset.
The numbers can differ from what you expect when the "join key field" is NOT unique...
Sample:
Tab1:
1 a
1 b
2 a
Tab2:
2 x
2 y
3 z
Will give from Tab1 -> Tab2:
1 a
1 b
Will give from Tab2 -> Tab1:
3 z
Clear ?
Nic;o)
The numbers can differ from what you expect when the "join key field" is NOT unique...
Sample:
Tab1:
1 a
1 b
2 a
Tab2:
2 x
2 y
3 z
Will give from Tab1 -> Tab2:
1 a
1 b
Will give from Tab2 -> Tab1:
3 z
Clear ?
Nic;o)
Have you tried using the unmatched query wizard?????
ASKER
So, if their are duplicates in the join field, this will cause issues? The join fields are not unique in either table... any suggestions now? :) Thanks a bunch!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again!
To keep things "clear" just create a new query based on your two mentioned above in the editor.
Now drag and drop the keyfield(s) to get the join.
Double-click this relation and select option 2 or 3, forcing qryActiveAssociatesIndivid
Now place the keyfield of the qryGetActiveServiceSupport
Clear ?
Nic;o)