?
Solved

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

Posted on 2013-02-04
5
Medium Priority
?
132 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
[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
5 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 38850952
Use an UPDATE statement
0
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 38850964
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
ID: 38850973
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
ID: 38850987
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
ID: 38851266
Perfect, thanks!
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

765 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