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. 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.
"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
"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
"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.
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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
|
by: Dam |
last post by:
Using SqlServer :
Query 1 :
SELECT def.lID as IdDefinition,
TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour
FROM serveur.Data_tblDEFINITIONTABLEDECODES def,...
|
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...
| |
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,...
|
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?
----------
|
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...
|
by: Eitan M |
last post by:
Hello,
How can I do outer join in ms-access database ?
Thanks :)
|
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,...
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |