473,378 Members | 1,280 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.

Joining a UNION to another Select

Hi there, been looking for a solution to this for some time now. I've
a UNION query that produces a table called AllSecurities:

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

I'd really like to show is all the fields from the Positions table,
but these don't exist in the Trades table, so they can't be included
in the UNION (as far as I know). Is it possible to link this to a:

SELECT Positions.* FROM Position;

by joining the 1st query to the 2nd by the use of:

LEFT JOIN Positions ON (AllSecurities.Book = Positions.Book) AND
(AllSecurities.SecurityNumber = Positions.SecurityNumber);

Thanks in advance for any advice given.

Andy.
Nov 12 '05 #1
2 2911
If you really need to, you can pad the select of Trades with dummy fields
(either Nulls, or "" for the text fields and 0 for the numeric ones):

SELECT SecurityNumber, Book, ATextField, ANumericField, AnotherTextField
FROM Positions
UNION
SELECT SecurityNumber, Book, NULL AS ATextField, NULL AS ANumericField, NULL
AS AnotherTextField FROM Positions

or

SELECT SecurityNumber, Book, ATextField, ANumericField, AnotherTextField
FROM Positions
UNION
SELECT SecurityNumber, Book, "" AS ATextField, 0 AS ANumericField, "" AS
AnotherTextField FROM Positions

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"Shaggy Dragon" <Sh***********@his.cave> wrote in message
news:b5********************************@4ax.com...
Hi there, been looking for a solution to this for some time now. I've
a UNION query that produces a table called AllSecurities:

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

I'd really like to show is all the fields from the Positions table,
but these don't exist in the Trades table, so they can't be included
in the UNION (as far as I know). Is it possible to link this to a:

SELECT Positions.* FROM Position;

by joining the 1st query to the 2nd by the use of:

LEFT JOIN Positions ON (AllSecurities.Book = Positions.Book) AND
(AllSecurities.SecurityNumber = Positions.SecurityNumber);

Thanks in advance for any advice given.

Andy.

Nov 12 '05 #2
On Sun, 16 Nov 2003 23:23:29 GMT, "Douglas J. Steele"
<NOSPAM_djsteele@NOSPAM_canada.com> wrote:
If you really need to, you can pad the select of Trades with dummy fields
(either Nulls, or "" for the text fields and 0 for the numeric ones):

SELECT SecurityNumber, Book, ATextField, ANumericField, AnotherTextField
FROM Positions
UNION
SELECT SecurityNumber, Book, NULL AS ATextField, NULL AS ANumericField, NULL
AS AnotherTextField FROM Positions

or

SELECT SecurityNumber, Book, ATextField, ANumericField, AnotherTextField
FROM Positions
UNION
SELECT SecurityNumber, Book, "" AS ATextField, 0 AS ANumericField, "" AS
AnotherTextField FROM Positions


Thanks for the suggestion, but there seems to be a problem:

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

returns 676 records whilst:

SELECT SecurityNumber, Book, SecurityDescription FROM Positions UNION
SELECT SecurityNumber, Book, NULL As SecurityDescription FROM Trades

Returns 928 records. There are a lot of duplicates present in the
table. I replaced NULL with "" with exactly the same result. Nearly
there, any other ideas I can try?

Thanks,

Andy.
Nov 12 '05 #3

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

Similar topics

3
by: Matt O'Donnell | last post by:
Does anyone know how I can 'join' the results of one SQL query to the bottom of another? Eg. I have two queries: 1. SELECT Name, Surname FROM People WHERE Surname = Smith NAME ...
4
by: Job Lot | last post by:
Is there anyway of Joining two or more DataTable with similar structure? I have three DataTables with following structures Data, AmountB/F, Repayments, InterestCharged and AmountC/F i want...
4
by: Elroyskimms | last post by:
Using SQL 2000... tblCustomer: CustomerID int CompanyName varchar(20) HasRetailStores bit HasWholesaleStores bit HasOtherStores bit tblInvoiceMessages:
3
by: james | last post by:
Hi, I would like to get all the records from 9 tables that have the same field value in one field (it is a unique field)that is shared by all the tables. Would this method of joining work: ...
2
by: Thomas R. Hummel | last post by:
Hello, I am currently working on a monthly load process with a datamart. I originally designed the tables in a normalized fashion with the idea that I would denormalize as needed once I got an...
6
by: das | last post by:
Hello all, I have a table with thousands of rows and is in this format: id col1 col2 col3 col4 --- ------ ----- ------ ------ 1 nm 78 xyz pir 2 ...
7
by: KoliPoki | last post by:
Hello every body. I have a small issue. Problem: I have a table with 4 descriptor columns (type). I need to formulate a query to retrieve a count for each type so I can group by...etc. The...
2
by: Alec | last post by:
Newbie question. Its really an SQL question, but have had no reply from the SQL newsgroup. I want to search the same table for two different criteria, and then join the search results...
2
by: Supermansteel | last post by:
I am joining these 2 tables together in Access 2003 and can't figure out the exact way of writing this script......Can anyone help? I have the following SQL: SELECT...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.