Solved

2 queries, 1 checks other for matching field and returns "yes"

Posted on 2013-02-04
5
126 Views
Last Modified: 2013-02-04
I have two access queries.

Query 1: List of peoples names plus a reference number.
Query 2: A list of reference numbers.

In query 1 i'd like to add another column that simply returns Yes and No.
Yes if the reference number matches any reference number in Query 2.
No if no match is found.

How do I do this?
0
Comment
Question by:antonioking
5 Comments
 
LVL 22

Expert Comment

by:plusone3055
Comment Utility
Use an UPDATE statement
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
Comment Utility
Try this:

SELECT q1.*,  IIF(q2.RefNumber IS NULL, "NO", "YES" ) AS RefInQuery2
FROM Query1 q1 LEFT JOIN Query2 q2 ON q1.RefNumber = q2.RefNumber

Open in new window

0
 
LVL 77

Expert Comment

by:peter57r
Comment Utility
Your version of....

SELECT query1.*, IIf(IsNull([query2].[reference]),"No","Yes") AS Matched
FROM Query1 LEFT JOIN Query2
ON Query1.Reference = query2.Reference;
0
 
LVL 22

Expert Comment

by:plusone3055
Comment Utility
First things first you have to run the 2nd query to get all the reference numbers and put them in a dummy table or a temp table

THEN do an update statement on the data table that query 1 is running against

so lets say that query 1 returns data from table1
query 2 returns data from table 2


UPDATE
[table1]
SET
column(yes/no) =
(
CASE
WHEN
(table1.id = table2.id)
'YES'
ELSE
column(yes/no) = NO
END
)
WHERE
table1.id <> NULL
0
 

Author Closing Comment

by:antonioking
Comment Utility
Perfect, thanks!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

728 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

10 Experts available now in Live!

Get 1:1 Help Now