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 January 3rd, 2006, 06:07 PM
Registered User
 
Join Date: Dec 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to join all records from both tables?

I've linked two tables, but found that there were only 3 types of links, However, what I what to do is to include all the records from both tables, how can I do that?

 
Old January 3rd, 2006, 09:30 PM
Authorized User
 
Join Date: Dec 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It sounds like you want to combine records from two tables (so if one contains records APPLE, ORANGE, PLUM, and the other contains records LETTUCE and ONION you want a single recordset containing APPLE, LETTUCE, ONION, ORANGE, and PLUM.
What you need is a "union query".

1) Make a query which selects the field(s) you want from the first table.
2) With the query open in design view, select SQL from the view menu.
3) If your table is called tblFruits the query's SQL will look something like this:

SELECT tblFruits.*
FROM tblFruits
ORDER BY tblFruits.Name;

4) To include another table called tblVegetables, change the code as follows:

SELECT tblFruits.*
FROM tblFruits

UNION SELECT tblVegetables.*
FROM tblVegetables
ORDER BY tblFruits.Name;

5) There's other customisation you can do - see the help file.
 
Old January 4th, 2006, 12:27 PM
Registered User
 
Join Date: Dec 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

very helpful. thanks a lot :D

 
Old January 4th, 2006, 12:39 PM
Registered User
 
Join Date: Dec 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can we make a new query out of this "union query"? if so, how to do it?
many many thanks!

 
Old January 4th, 2006, 01:36 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you're using VBE it works the same as any other query, if you're using the Query Designer simply change the view to SQL View and enter the code as shown above.






Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Join tables help tdaustin Classic ASP Databases 2 January 11th, 2006 04:57 PM
how to inner join tables gilgalbiblewheel Classic ASP Databases 4 January 31st, 2005 08:04 PM
Join Tables tdaustin Classic ASP Basics 1 May 25th, 2004 07:31 AM
Inner Join multiple tables qwprince Classic ASP Databases 5 July 23rd, 2003 02:33 PM





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