473,666 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UNION - seeing fields from both tables

Hi,
A couple of guys on the SQL Server forum solved this one yesterday but
they used a FULL OUTER JOIN, which, little known to me is missing from
Accesss and therefore the JET engine. Can anyone suggest an Access
friendly version? I'd like to be able to see other fields from both
UNIONed tables. For instance :

Positions table:

Book SecurityNumber Description
A 001 Fred
B 002 Jim
B 003 Tom
D 005 Peg
E 006 Sally

Trades Table:

Book SecurityNumber Value
A 001 1000
A 001 3000
C 004 4000
E 006 8000

Output Should look like:

Book SecurityNumber Description Value
A 001 Fred 1000
B 002 Jim
B 003 Tom
C 004 4000
D 005 Peg
E 006 Sally 8000

The linking fields are Book and SecurityNumber via a:

SELECT SecurityNumber, Book FROM Trades UNION
SELECT SecurityNumber, Book from Positions;

Is this possible? Really I'd like to be able to generate a union
query that includes * from both tables and has nulls where a record is
missing from the other table.

Thanks in advance for any help given.

Andy.
Nov 12 '05 #1
3 2633
Try UNION ALL ...

"Andy S" <to***@btintern et.com> wrote in message
news:u1******** *************** *********@4ax.c om...
Hi,
A couple of guys on the SQL Server forum solved this one yesterday but
they used a FULL OUTER JOIN, which, little known to me is missing from
Accesss and therefore the JET engine. Can anyone suggest an Access
friendly version? I'd like to be able to see other fields from both
UNIONed tables. For instance :

Positions table:

Book SecurityNumber Description
A 001 Fred
B 002 Jim
B 003 Tom
D 005 Peg
E 006 Sally

Trades Table:

Book SecurityNumber Value
A 001 1000
A 001 3000
C 004 4000
E 006 8000

Output Should look like:

Book SecurityNumber Description Value
A 001 Fred 1000
B 002 Jim
B 003 Tom
C 004 4000
D 005 Peg
E 006 Sally 8000

The linking fields are Book and SecurityNumber via a:

SELECT SecurityNumber, Book FROM Trades UNION
SELECT SecurityNumber, Book from Positions;

Is this possible? Really I'd like to be able to generate a union
query that includes * from both tables and has nulls where a record is
missing from the other table.

Thanks in advance for any help given.

Andy.

Nov 12 '05 #2
tom
Andy -

Here's my guess:

=============== =============== ============
SELECT p.Book, p.SecurityNumbe r, p.Description, t.Value
FROM Positions as p
LEFT JOIN Trades as t
ON (t.Book = p.Book) And (t.SecurityNumb er = p.SecurityNumbe r)
UNION ALL
SELECT t.Book, t.SecurityNumbe r, p.Description, t.Value
FROM Positions as p
RIGHT JOIN Trades as t
ON (t.Book = p.Book) And (t.SecurityNumb er = p.SecurityNumbe r)
WHERE p.Book Is Null
=============== =============== ============

The 1st Select gets all the records in Positions, whether they match
in Trades or not, and the 2nd Select gets all the records in Trades
that are not in Positons.

-Tom

untested air code...
Nov 12 '05 #3
Thank you so much Tom, it works perfectly. Now to add another 300
JOINs to it ;)

Thanks again,

Andy.

On 18 Nov 2003 14:25:16 -0800, to*@nuws.com (tom) wrote:
Andy -

Here's my guess:

============== =============== =============
SELECT p.Book, p.SecurityNumbe r, p.Description, t.Value
FROM Positions as p
LEFT JOIN Trades as t
ON (t.Book = p.Book) And (t.SecurityNumb er = p.SecurityNumbe r)
UNION ALL
SELECT t.Book, t.SecurityNumbe r, p.Description, t.Value
FROM Positions as p
RIGHT JOIN Trades as t
ON (t.Book = p.Book) And (t.SecurityNumb er = p.SecurityNumbe r)
WHERE p.Book Is Null
============== =============== =============

The 1st Select gets all the records in Positions, whether they match
in Trades or not, and the 2nd Select gets all the records in Trades
that are not in Positons.

-Tom

untested air code...


Nov 12 '05 #4

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

Similar topics

3
3556
by: Paradigm | last post by:
I am using Access 2K as a front end to a MYSQL database. I am trying to run a Union query on the MYSQL database. The query is (much simplified) SELECT as ID from faxdata UNION SELECT as ID from letdata UNION SELECT as ID FROM MEMODATA; I get an ODBC error. The same query runs when the backend files are MDB files and it runs with MYSQL if I only combine 2 tables.
2
10744
by: Gerry | last post by:
I am relatively new to DB2 and having a problem with a simple union statement. Running Db2UDB version 8.1.1 on Aix 5.1 The union and union all SQL statements I am running produce the same results. No duplicates are being eliminated in the union. To verify, I ran SQL with union statements against system tables.
3
10540
by: Dalan | last post by:
From reading Access 97 help text, it seems that to do what I need to do will require a Union Query. As this would be my first, I think I might require a little guidance. I have two tables with 10 fields that have like data (for instance both have an item description field, an item price field, a general notes field, etc.) but with different field names. The tables have approximately 20/40 other fields that are dissimilar and not needed...
4
2929
by: shaun palmer | last post by:
when or Where do you use a union query ? how can I wright sql, tblPopulation,* tblcustomer,* one to one with all the appropriate attributes(field). Your help would be greatly appreciated. Thank you.
1
2002
by: PATGMorris | last post by:
I've got a Union Query that pulls data from two different tables for chemistry and micro testing. The tables containing very similar data but for reasons not necessary here, cannot be put into one table (differing types of results mainly) However, both have date entry fields for varying time stations from an initial, 2 weeks, 1 month, 2 months through to 24 months. I've written a Union Query that pulls the dates into a sort of ...
2
2730
by: Lyn | last post by:
Hi, How do you bind the output columns from a UNION query when the fields from the two tables have different names? Consider this query (WHERE clauses omitted)... SELECT SurnameBirth, FNameBirth, DOB, 'Birth' from tblBirth UNION SELECT SurnameAlias, FNameAlias, #1/1/100#, 'Alias' from tblAlias; What I am doing here is searching two tables for a person where the name given may be the person's original name (at birth) or subsequent...
5
3290
by: Lyn | last post by:
This one is difficult to explain, so I will cut it down to the basics. I have a major table 'tblA' which has an autonum field 'ID-A' as primary key (of no significance to users). 'tblA' contains many fields including picture and memo fields. The main user-selectable field is 'NameA'. There is also a crossreference table (let's call it 'tblB') which provides a secondary method of accessing records in 'tblA'. The main fields in 'tblB'...
2
4340
by: mattytee123 | last post by:
I have about 20 tables, of which I would like to do a union query and count of how many of each different code there is? The simplified verson of the table is structured like this. Code Count 1234 1 2468 1 1234 1 2468 1
3
2220
by: mikes | last post by:
I have 2 separate queries, which effectively are the same except they draw data from separate tables. Both tables are (design-wise) identical, only the data is different. for each query, there are 2 tables with a standard LEFT JOIN. One field of the query is calculated, looking for a NULL in one table, and then using a field from the second table in that case. One query looks like this: PARAMETERS Text ( 255 ); SELECT...
0
8443
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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,...
0
8866
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, 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...
0
7385
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6192
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 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...
0
5663
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();...
0
4198
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.