RE: filter for values in another table
- From: Dale Fye <dale.fye@xxxxxxxxxx>
- Date: Mon, 10 Dec 2007 07:30:02 -0800
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: Qaspec
- RE: filter for values in another table
- Prev by Date: RE: Updateable Query
- Next by Date: RE: how to populate a listboc with the result of two combobox
- Previous by thread: Creating update query to update non primary key.
- Next by thread: RE: filter for values in another table
- Index(es):
Relevant Pages
|
Loading