Solved

Create Subset of Table Based on Two Fields

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

Accepted Solution

by:
Rey Obrero 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now