473,804 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Secur ityNumber);

Thanks in advance for any advice given.

Andy.
Nov 12 '05 #1
2 2934
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, AnotherTextFiel d
FROM Positions
UNION
SELECT SecurityNumber, Book, NULL AS ATextField, NULL AS ANumericField, NULL
AS AnotherTextFiel d FROM Positions

or

SELECT SecurityNumber, Book, ATextField, ANumericField, AnotherTextFiel d
FROM Positions
UNION
SELECT SecurityNumber, Book, "" AS ATextField, 0 AS ANumericField, "" AS
AnotherTextFiel d 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.c om...
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.Secur ityNumber);

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_djsteel e@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, AnotherTextFiel d
FROM Positions
UNION
SELECT SecurityNumber, Book, NULL AS ATextField, NULL AS ANumericField, NULL
AS AnotherTextFiel d FROM Positions

or

SELECT SecurityNumber, Book, ATextField, ANumericField, AnotherTextFiel d
FROM Positions
UNION
SELECT SecurityNumber, Book, "" AS ATextField, 0 AS ANumericField, "" AS
AnotherTextFie ld 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, SecurityDescrip tion FROM Positions UNION
SELECT SecurityNumber, Book, NULL As SecurityDescrip tion 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
12887
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 SURNAME
4
4297
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 to join these tables on the basis of Date. I don't want three rows for each date, i want the values to be added for similar dates. thanx
4
6955
by: Elroyskimms | last post by:
Using SQL 2000... tblCustomer: CustomerID int CompanyName varchar(20) HasRetailStores bit HasWholesaleStores bit HasOtherStores bit tblInvoiceMessages:
3
4479
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: select * from table 1, table 2, table 3 where table 1.com_field = table 2.com_field and table 2.com_field = table 3.com_field
2
1986
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 idea of what the performance was like. There were some performance problems, so the decision was made to denormalize. Now the users are happy with the query performance, but loading the tables is much more difficult. Specifically...
6
4598
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 bn 45 abc dir I now want to get the data from this table in this format:
7
3318
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 view I have works, but doesn't work when I supplement the query with some functions... they just don't like the UNION. The real problem is I can't change any of the udf's or queries, just the view. The view is inner joined back on to the primary...
2
1678
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 together into one new list. See below. <?php
2
2269
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 PL_Input.Date_ID,Count(PL_Input.+PL_Input.+PL_Input.+PL_Input.+PL_Input.) AS FROM Country INNER JOIN PL_Input ON Country.Country_ID = PL_Input.Country_ID WHERE (((. & "" & . & "" & . & "" & . & "" & .) Like "*2*"))
0
9594
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
10350
jinu1996
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...
1
10351
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,...
0
10096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9174
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
7638
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
5534
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
4311
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
3
3002
bsmnconsultancy
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...

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.