Solved

Create Subset of Table Based on Two Fields

Posted on 2008-09-29
4
321 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

856 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