473,511 Members | 9,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A double outer join?

Using an outer join, a query can return all records from Table1 and only
those matching from Table2 (or vice versa). How can I write a query that
will return unmatched records from both sides? For example:

Table1
Key Data
----------
123 Bill
124 Tom
125 Joe

Table2
Key Data
----------
121 Ed
123 Bill
124 Tom

Query Output:
Key T1 T2
------------
121 Null Ed
123 Bill Bill
124 Tom Tom
125 Joe Null

Thanks for any help.
Nov 12 '05 #1
5 12937
"Randy Harris" <ra***@SpamFree.com> wrote in message
news:J%********************@newssvr28.news.prodigy .com...
Using an outer join, a query can return all records from Table1 and only
those matching from Table2 (or vice versa). How can I write a query that
will return unmatched records from both sides? For example:


It's called a full outer join and Access don't do 'em. So do a union of a
left outer and a right outer:

SELECT Table1.ID, Table1.text, Table2.text
FROM Table1 LEFT JOIN Table2 ON Table1.ID = Table2.ID

UNION

SELECT Table2.ID, Table1.text, Table2.text
FROM Table1 RIGHT JOIN Table2 ON Table1.ID=Table2.ID;

HTH, Mike MacSween

Why? by the way.
Nov 12 '05 #2
"Randy Harris" <ra***@SpamFree.com> wrote in
news:J%********************@newssvr28.news.prodigy .com:
Using an outer join, a query can return all records from
Table1 and only those matching from Table2 (or vice versa).
How can I write a query that will return unmatched records
from both sides? For example:

there may be other ways, but I create a union query with one field,
the Key from each table, and do an outer join to each source table
in a second query.

Query 1:
SELECT mykey from table1
UNION select mykey from table2
UNION select mykey from table3
;

Query 2:
SELECT query1.mykey table1.* table2.* from query1 left join
table1...

Bob

Nov 12 '05 #3

"Mike MacSween" <mi******************@btinternet.com> wrote in message
news:3f***********************@news.aaisp.net.uk.. .
"Randy Harris" <ra***@SpamFree.com> wrote in message
news:J%********************@newssvr28.news.prodigy .com...
Using an outer join, a query can return all records from Table1 and only
those matching from Table2 (or vice versa). How can I write a query that will return unmatched records from both sides? For example:
It's called a full outer join and Access don't do 'em. So do a union of a
left outer and a right outer:

SELECT Table1.ID, Table1.text, Table2.text
FROM Table1 LEFT JOIN Table2 ON Table1.ID = Table2.ID

UNION

SELECT Table2.ID, Table1.text, Table2.text
FROM Table1 RIGHT JOIN Table2 ON Table1.ID=Table2.ID;

HTH, Mike MacSween


Mike, I haven't tried this yet, but I have a question. Won't that give me
double entries for any records where the IDs do happen to match up?
Why? by the way.


Hmm. Two separate applications, two separate databases. Someday I hope to
have them combined into a single database, but in the meantime I have the
users manually entering the PK-ID's from one system into the other as
records get created so that I have something to join them with. To help
correct entry errors, I've written queries that find unmatched records, but
it becomes difficult to find the record that should be linked in the other
database. A single query that shows both sides, with both the matched and
the unmatched records, will help in tracking down errors.

Thanks for the help,
Randy Harris
Nov 12 '05 #4
"Randy Harris" <ra***@SpamFree.com> wrote in message
news:HS********************@newssvr28.news.prodigy .com...

"Mike MacSween" <mi******************@btinternet.com> wrote in message
news:3f***********************@news.aaisp.net.uk.. .

It's called a full outer join and Access don't do 'em. So do a union of a left outer and a right outer:

SELECT Table1.ID, Table1.text, Table2.text
FROM Table1 LEFT JOIN Table2 ON Table1.ID = Table2.ID

UNION

SELECT Table2.ID, Table1.text, Table2.text
FROM Table1 RIGHT JOIN Table2 ON Table1.ID=Table2.ID;

HTH, Mike MacSween


Mike, I haven't tried this yet, but I have a question. Won't that give me
double entries for any records where the IDs do happen to match up?


Please ignore that, I tried it and it does exactly what you said. Thanks.

Nov 12 '05 #5
"Randy Harris" <ra***@SpamFree.com> wrote in message
news:FR********************@newssvr28.news.prodigy .com...
"Randy Harris" <ra***@SpamFree.com> wrote in message
news:HS********************@newssvr28.news.prodigy .com...

"Mike MacSween" <mi******************@btinternet.com> wrote in message
news:3f***********************@news.aaisp.net.uk.. .

It's called a full outer join and Access don't do 'em. So do a union
of
a left outer and a right outer:

SELECT Table1.ID, Table1.text, Table2.text
FROM Table1 LEFT JOIN Table2 ON Table1.ID = Table2.ID

UNION

SELECT Table2.ID, Table1.text, Table2.text
FROM Table1 RIGHT JOIN Table2 ON Table1.ID=Table2.ID;

HTH, Mike MacSween


Mike, I haven't tried this yet, but I have a question. Won't that give me double entries for any records where the IDs do happen to match up?


Please ignore that, I tried it and it does exactly what you said. Thanks.


Yes, UNION doesn't return duplicates unless you use UNION ALL

Mike
Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
18103
by: Martin | last post by:
I am now working on SQL Server 2000 having had previous experience on a different database. Both of the OUTER JOIN syntaxes is different from what I am used to and I am finding it slightly...
8
4962
by: Matt | last post by:
Hello I have to tables ar and arb, ar holds articles and a swedish description, arb holds descriptions in other languages. I want to retreive all articles that match a criteria from ar and...
4
4845
by: thilbert | last post by:
All, I have a perplexing problem that I hope someone can help me with. I have the following table struct: Permission ----------------- PermissionId Permission
3
10041
by: Dam | last post by:
Using SqlServer : Query 1 : SELECT def.lID as IdDefinition, TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour FROM serveur.Data_tblDEFINITIONTABLEDECODES def,...
3
19458
by: Martin | last post by:
Hello everybody, I have the following question. As a join clause on Oracle we use " table1.field1 = table2.field1 (+) " On SQL Server we use " table1.field1 *= table2.field1 " Does DB2...
3
7521
by: deko | last post by:
From what I understand, an Inner Join narrow the rows selected to the table with the least results... and an Outer Join does the opposite... SELECT qryTxToQ1.Q1Total, qryTxToQ2.Q2Total,...
5
2270
by: Dev | last post by:
Hello all, I need to do a left out join where a.field1 ilike %b.field2% But I can not figure out the exact syntax to using the ilike in the join? ----------
1
10415
by: Andreas Bauer | last post by:
Hi, when I try a left outer join on one table everything works fine: select * from (tourist.users u left outer join tourist.user_extended_info ue on (u.id = ue.id)) But now I need to do...
5
3270
by: Eitan M | last post by:
Hello, How can I do outer join in ms-access database ? Thanks :)
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.