RE: filter for values in another table
- From: Qaspec <Qaspec@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 10 Dec 2007 09:18:02 -0800
"2. The other way is to use the IN Clause in your SQL statement. It would
look like:
SELECT TableA.*
FROM TableA
WHERE TableA.ID NOT IN (SELECT DISTINCT ID FROM TableB)"
Would I just enter all of the ids into the parenthesis? or would i create a
select statement for each id that i want to exclude from the results?
"Dale Fye" wrote:
Sure,.
There are a couple of ways to do this.
1. The first, and probably fastest with regards to how quickly your query
runs is to create a query that some people call a "frustrated outer join".
In this type of query, you are looking for those records in one table that
are not in another. The syntax looks something like:
SELECT TableA.*
FROM TableA LEFT JOIN TableB
ON TableA.ID = TableB.ID
WHERE TableB.ID IS NULL
To create this query in the query grid, bring both tables A and B into a new
query.
Create a join between the ID fields of the two tables, then right click on
the join line and select Join Properties. In the dialog that pops up, select
the option that say "Include ALL records FROM TableA and only those records
from TableB where the joined fields are equal". I know this may seem counter
intuitive based on the description, but trust me.
Drag the fields you want from TableA, and the ID field from TableB into the
query grid. If you run the query now, the column corresponding to the
TableB.ID will contain some values, and other NULL values. If you want the
records where the ID is in A and not in B, then in the criteria row for
TableB.ID, type "Is NULL" (without the quotes).
2. The other way is to use the IN Clause in your SQL statement. It would
look like:
SELECT TableA.*
FROM TableA
WHERE TableA.ID NOT IN (SELECT DISTINCT ID FROM TableB)
HTH
Dale
--
Don''t forget to rate the post if it was helpful!
email address is invalid
Please reply to newsgroup only.
"Qaspec" wrote:
In my query i have records that contain a field named "id" from all the
records in table a. In table b i have a list of ids that i would like to
exclude from the list of records that return from table a in my query. Can i
set the filter to look for the values in my table instead of typing out 50
ids in the criteria section? How would that be done?
- Follow-Ups:
- RE: filter for values in another table
- From: Dale Fye
- RE: filter for values in another table
- References:
- RE: filter for values in another table
- From: Dale Fye
- RE: filter for values in another table
- Prev by Date: Re: adding a toolbar to a specific query
- Next by Date: RE: how to populate a listboc with the result of two combobox
- Previous by thread: RE: filter for values in another table
- Next by thread: RE: filter for values in another table
- Index(es):
Relevant Pages
|