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 12957
"Randy Harris" <ra***@SpamFree .com> wrote in message
news:J%******** ************@ne wssvr28.news.pr odigy.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=Table 2.ID;
HTH, Mike MacSween
Why? by the way.
"Randy Harris" <ra***@SpamFree .com> wrote in
news:J%******** ************@ne wssvr28.news.pr odigy.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************ ******@btintern et.com> wrote in message
news:3f******** *************** @news.aaisp.net .uk... "Randy Harris" <ra***@SpamFree .com> wrote in message news:J%******** ************@ne wssvr28.news.pr odigy.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=Table 2.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******** ************@ne wssvr28.news.pr odigy.com... "Mike MacSween" <mi************ ******@btintern et.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=Table 2.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******** ************@ne wssvr28.news.pr odigy.com... "Randy Harris" <ra***@SpamFree .com> wrote in message news:HS******** ************@ne wssvr28.news.pr odigy.com... "Mike MacSween" <mi************ ******@btintern et.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=Table 2.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 confusing.
For example, given two tables :
wipm_tbl_mi
wipm_tbl_wi (which may not have data in it for a specific record that
exists in the first table.)
|
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 also
display their corresponding entries in arb, but if there is NO entry
in arb I still want it to show up as NULL or something, so that I can
get the attention that there IS no language associated with that
article.
|
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,
serveur.Data_tblTABLEDECODEAUNEVALEUR TDC_AUneValeur
where def.TYPEDETABLEDECODES = 4
|
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 have the same type of operator, without using the OUTER JOIN
syntax ?
| |
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, qryTxToQ3.Q3Total,
qryTxToQ4.Q4Total
FROM qryTxToQ4 OUTER JOIN (qryTxToQ3 OUTER JOIN (qryTxToQ1 OUTER JOIN
qryTxToQ2 ON qryTxToQ1.TxAcct_ID = qryTxToQ2.TxAcct_ID) ON
qryTxToQ3.TxAcct_ID = qryTxToQ2.TxAcct_ID) ON qryTxToQ4.TxAcct_ID =
qryTxToQ3.TxAcct_ID;
|
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 another left outer join with a third table, but
this doesn't work (although I found a tutorial on sql where it was
described that way):
|
by: Eitan M |
last post by:
Hello,
How can I do outer join in ms-access database ?
Thanks :)
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |