Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / April 2008

Tip: Looking for answers? Try searching our database.

How to do a left and right join together?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Grd - 16 Apr 2008 19:18 GMT
Hi there,

I have a query and I want both the results I get with option 2 and option 3
which as I understand is the left and right join.

I'm told its possible however there are only three choices.

could anyone advise me - its really something I need

Thanks

Suzanne
George Nicholson - 16 Apr 2008 19:44 GMT
a 4th unstated option is a "no-join" Cartesian result set: all possible
combinations

Given: one table with employees (100 records) and one table with DayOfWeek
(7 records)
- Add both tables to query. No join between tables
- Add Employee name, Day of week fields to query
- Run query
- result would be a listing of all employees for each day of week ( 700
records)

Signature

HTH,
George

> Hi there,
>
[quoted text clipped - 9 lines]
>
> Suzanne
Grd - 17 Apr 2008 03:37 GMT
Thanks George,

The cartesian doesn't work for what I want here but its a very interesting
technique.
Thanks. Dale 'full outer join' gives me the results I'm after.

> a 4th unstated option is a "no-join" Cartesian result set: all possible
> combinations
[quoted text clipped - 20 lines]
> >
> > Suzanne
Dale Fye - 16 Apr 2008 19:51 GMT
Suzanne,

I think what you are referring to is a "Full Outer Join".  Assuming that you
have two tables that are similar, but contain records that may or may not
correspond, and you want to creat a query that has all the records from A and
B.  Unfortunately, Access does not have a simple way to accomplish this.  

However, the approved workaround is not too difficult.

1.  Generally, I start by creating the left join:

SELECT A.Field1, A.Field2, A.Field3, B.Field4
FROM tableA as A LEFT JOIN tableB as B
ON A.Field1 = B.Field1

This will give you all the records from A, and only those from B that match.

2.  Then go to the SQL view and add the following:

UNION
SELECT B.Field1, B.Field2, B.Field3, B.Field4
FROM tableB as B LEFT JOIN tableA as A
ON B.Field1 = A.Field1
WHERE A.Field1 IS NULL

3.  So the final query would look like

SELECT A.Field1, A.Field2, A.Field3, B.Field4
FROM tableA as A LEFT JOIN tableB as B
ON A.Field1 = B.Field1
UNION
SELECT B.Field1, B.Field2, B.Field3, B.Field4
FROM tableB as B LEFT JOIN tableA as A
ON B.Field1 = A.Field1
WHERE A.Field1 IS NULL

Keep in mind, that in a UNION query, you have to have the same number of
fields in each portion of the union, and the field types must correspond.

If this doesn't answer your need, post back with more info on the two tables
(fields) you want to include in the query, and we'll see what we can do.
Signature

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.

> Hi there,
>
[quoted text clipped - 8 lines]
>
> Suzanne
Grd - 17 Apr 2008 03:36 GMT
Works

Thanks
dale

> Suzanne,
>
[quoted text clipped - 50 lines]
> >
> > Suzanne
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.