Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-02-04
5
Medium Priority
?
133 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

610 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