Solved

Create Subset of Table Based on Two Fields

Posted on 2008-09-29
4
334 Views
Last Modified: 2012-05-05
Here are some easy points for someone smarter than myself, which probably includes most reading this question!

I have two tables (tblResults and tblRequested) that share 3 common fields: SampleID, AnalyteID, Requested. Although none of the shared fields is unique in either table, the combination of SampleID and AnalyteID IS unique. For example, there are many occurrences of SampleID=14 and many of AnalyteID=3, but there will only ever be one record where SampleID=14 AND AnalyteID=3.

Some of the records in tblRequested correspond (based on SampleID and AnalyteID) to records in tblResults. But some records do not. I would like to create a query that selects those records in tblRequested which are not found in tblResults, based on the values SampleID and AnalyteID.

Thanks in advance!
0
Comment
Question by:Gazaway
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 22600605


try this query

select tblRequested.*
from tblRequested LEFT join tblResults ON (tblRequested.SampleID = tblResults.SampleID) and (tblRequested.AnalyteID = tblResults.AnalyteID)
where ((tblResults.SampleID) Is null) and (tblResults.AnalyteID) Is null))
0
 
LVL 4

Expert Comment

by:mrnev
ID: 22600622
You can use a left outer join in your query combined with a null check on a field in tblresults that should always be filled in to do this.  Something like

Select TblRequested.* from TblRequested left join tblResults on tblrequested.sampleid = tblresults.sampleid and tblrequested.analyteid = tblresults.analyteid
where (tblresults.analyteid is null)
0
 
LVL 14

Expert Comment

by:pteranodon72
ID: 22600763
Access Wizards will take you halfway there for this one.

Insert menu->Query
Choose "Find Unmatched Query Wizard"

On the first screen, you'll choose Table: tblRequested

On the next screen, you'll choose Table: tblResults

On the next screen you match up fields between tables.  The wizard will only allow you to match one field, but you can do the other later.  Therefore, select SampleID on both tables and press the <=> and click Next

Choose all the fields from tblRequested that you want to appear in the end. (next)
On the final screen, name the query and choose Modify (finish)

---
You'll see a query design with tblRequested on the left and tblResults on the right.  A arrow points from tblRequested.SampleID --> tblResults.SampleID.

What you need to do is drag the field tblRequested.AnalyteID and drop it on tblResults.AnalyteID.  Then, you'll choose the option that shows all rows from tblRequested but only those from tblResults that match.

You'll now see a similiar arrow connecting the tables.

Drag tblResults.AnalyteID down to the grid, enter Is Null in the top row of criteria and clear the Show checkbox.
---
You may need to repeat these steps with Requested, I can't tell from your description.

HTH,

Pteranodon
0
 

Author Comment

by:Gazaway
ID: 22601136
First come, first tried: capricorn1's solution did the trick! I had to tweak the last line to eliminate some parentheses problems. The corrected line is shown below:

WHERE (((tblResults.SampleID) Is Null) AND ((tblResults.AnalyteID) Is Null));

I add this only for documentation purposes and for someone else referencing this question. The solution itself was perfect!

Thanks to all who responded!
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question