Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 24th, 2012, 10:03 AM
Registered User
 
Join Date: Oct 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Access: bring value from another table?

Hello everyone! This forum is extreamly helpful.

I would like to bring value from one table to another, but preserving records that do not have matches in the later.

Example:
Table1 has two columns - ACC and TERR
ACC | TERR
1 | N1
2 | NS
3 | AR

Table2 has one column - ACC
ACC
1
2
3
4
5

I would like to match the TERR column in Table1 to Table2, based on ACC#.
However, I would like to be able to see the full list of account in the resulting query.

The resulting query should look like:
QueryT1T2
ACC | TERR
1 | N1
2 | NS
3 | AR
4 |
5 |


Please help!
 
Old October 24th, 2012, 10:42 AM
Authorized User
 
Join Date: Oct 2010
Posts: 64
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Hi JoeBB,

This is what a LEFT OUTER JOIN is used for.

Try

SELECT t2.ACC, t1.TERR
FROM Table2 t2 LEFT OUTER JOIN Table1 t1 ON t2.ACC = t1.ACC;

HTH.

Malc.
The Following User Says Thank You to malcolmdixon For This Useful Post:
JoeBB (October 24th, 2012)
 
Old October 24th, 2012, 11:12 AM
Registered User
 
Join Date: Oct 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Malcolm Dixon View Post
Hi JoeBB,

This is what a LEFT OUTER JOIN is used for.

Try

SELECT t2.ACC, t1.TERR
FROM Table2 t2 LEFT OUTER JOIN Table1 t1 ON t2.ACC = t1.ACC;

HTH.

Malc.
Hi Malcolm! Thank you for the reply.

Would you please explain where I should place this expression in and how dod I do that?
Thanks!
 
Old October 24th, 2012, 12:54 PM
Registered User
 
Join Date: Oct 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Placed it in the SQL: Open new query in design view> go to View> SQL >

SELECT T2.ACC, T1.TERR
FROM T2 LEFT JOIN T1 ON T2.ACC = T1.ACC;

It auto build table relationship between tables in access 2003. My understanding is that this is not permanent relationship and is usually not visible in access 2007 and up.


Additionally, it is important to note that we have to delete any existing relationships between table T1 and T2 to execute the query above.
Could you confirm this, Malcolm?


Works with little name modifications!
You are a genious!
Thank you so much!
Thanks sent!

Last edited by JoeBB; October 24th, 2012 at 01:01 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
New employee: Access qry won't bring back value? SunnySide Access VBA 13 November 15th, 2011 07:45 PM
bring to front dkr72 Excel VBA 1 December 2nd, 2004 05:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.