473,378 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

"either" join option

There are normally 3 join options in Access:

1. Records must be found in both tables
2. Records must be found in table "x", but not table "y"
3. Records must be found in table "y", but not table "x"

Is there a join option that includes all unique records from both tables?
Oct 11 '10 #1
10 2297
nico5038
3,080 Expert 2GB
Use a INNER JOIN, LEFT JOIN and RIGHT JOIN query and combine them with a UNION.

Access has no OUTER JOIN :-(

Nic;o)
Oct 11 '10 #2
NeoPa
32,556 Expert Mod 16PB
Have a look at SQL JOINs for more on this.

Access doesn't support the FULL OUTER JOIN, which is what you're referring to, though other database engines do.

Nico's idea, to overlap multiple joins, can work in almost all cases. It wouldn't need the INNER JOIN, as this is a subset of both the LEFT JOIN and the RIGHT JOIN. That said, it should do the job for you. I mentioned almost all cases, as there is overlap where [Table A] and [Table B] match. To avoid duplicating the records it is necessary to use the UNION version, as opposed to the UNION ALL version, in a case like this. In most cases this is fine, but there can be data sets where there are duplicates occuring validly, which this would effect (by removing the duplicates - even the valid ones).
Oct 11 '10 #3
nico5038
3,080 Expert 2GB
Oops, good remark NeoPa. Was anticipating to add an additonal TypeJoin variable in the queries indicating the source (Inner/Left/Right). This would however require the LEFT and RIGHT JOIN to test for a missing key in the "opposite" table.

Nic;o)
Oct 11 '10 #4
NeoPa
32,556 Expert Mod 16PB
Good idea Nico.

You could still do this without the INNER JOIN though (unless you needed to use UNION ALL). Any record where both keys were non-Null would be flagged as INNER.

With a UNION ALL, then all types of joins would be required and the WHERE clause would be also be required for the OUTER joins (LEFT JOIN & RIGHT JOIN) to ensure none of the INNER JOIN records were repeated.
Oct 11 '10 #5
nico5038
3,080 Expert 2GB
"You could still do this without the INNER JOIN"
No, as you'll get the same "match" for both LEFT and RIGHT, now with a different literal....
The exclusion with a test for the missing foreignkey is essential.

Nic;o)
Oct 11 '10 #6
NeoPa
32,556 Expert Mod 16PB
My understanding is that this is only a problem when using UNION ALL. When using the UNION alone, the duplicates are dropped anyway, so it wouldn't matter that the same records are found in both the LEFT and RIGHT OUTER JOINs. The literal in each case would be "INNER JOIN". I did cover the UNION ALL scenario in my post. I suspect that is the one you were expecting to be used for your suggestion.
Oct 11 '10 #7
nico5038
3,080 Expert 2GB
When having:
Expand|Select|Wrap|Line Numbers
  1. select "match" as Type, * from tblA INNER JOIN ...
  2. UNION 
  3. select "Left", * from tblA LEFT JOIN
  4. UNION 
  5. select "Right", * from tblA RIGHT JOIN
  6.  
Will force the UNION (without "ALL") to find always a difference in the rows that match when not excluding them....

Nic;o)
Oct 11 '10 #8
NeoPa
32,556 Expert Mod 16PB
That would result in any matches appearing three times though (As a matching pair would appear in each inner recordset regardless of the JOIN type). Is this your intention?

I would expect something like :
Expand|Select|Wrap|Line Numbers
  1. SELECT IIf(tblB.ID Is Null, 'Left', 'Match') AS [Type]
  2.      , tblA.*
  3. FROM   tblA LEFT JOIN tblB
  4.   ON   tblA.ID = tblB.ID
  5. UNION
  6. SELECT IIf(tblA.ID Is Null, 'Right', 'Match')
  7.      , tblB.*
  8. FROM   tblA RIGHT JOIN tblB
  9.   ON   tblA.ID = tblB.ID
Clearly, I've made some basic assumptions about how the tables are linked with an [ID] field, etc. Also, as your example uses fields from only a single table, that both tables hold similar data in the same fields.

For this question I would expect the fields from both [tblA] and [tblB] to be required in the SELECT clause. The question isn't specific on that score, but that would be my guess.
Oct 11 '10 #9
nico5038
3,080 Expert 2GB
As always there are multiple ways to achieve the same.

I would add a WHERE clause on the Left/Right join queries to filter only the mismatches. Thus UNION or UNION ALL don't make a difference but you'll need three queries. Your solution needs the roll-up of the UNION, but is indeed shorter :-)

Nic;o)
Oct 11 '10 #10
NeoPa
32,556 Expert Mod 16PB
I do understand what you're saying Nico (See post #5), and you're right. There are so many ways to handle this, but the appropriate ones nearly always depend on knowing the precise details of the question (which we rarely do of course). It's always fun discussing things in finer detail with someone who knows the stuff as well as you do.
Oct 11 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

32
by: Nuno Paquete | last post by:
Hi group. I'm using this code to see if is there any parameter for variable "menu": if($_GET == "downloads") .... But this code log errors if there is no parameter passed (this heappens at...
27
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a...
5
by: Jeremy | last post by:
I am relatively inexperienced with SQL, and I am trying to learn how to analyze some data with it. I have a table with the following information. COMPANY ID , DATE, MarektValue I would like...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
3
by: Dam | last post by:
Using SqlServer : Query 1 : SELECT def.lID as IdDefinition, TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour FROM serveur.Data_tblDEFINITIONTABLEDECODES def,...
7
by: DC Gringo | last post by:
I am having a bear of a time with setting a URL query string as a text value in a dropdownlist and Server.URLEncode does not seem to do its job. theFullLink = theLinkPrefix &...
3
by: William | last post by:
I tried to update a scrolling_list with the following: function saveText( scroll_list, t_area, listToBeUpdated ) { var updated = new Option(); updated.value = t_area.value; updated.text =...
59
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
2
by: Angus | last post by:
I am trying to change the selection in Javascript - but this HTML element is not a standard option control. On the web page it looks like a dropdown list - and you click on the right hand down...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.