Adding more fields to a Union Query (1 Viewer)

Coldsteel

Registered User.
Local time
Today, 08:39
Joined
Feb 23, 2009
Messages
73
Hello all,

I have a question I have table with the following fields listed below

Inv ()
ID Area Hosting Pc_SN Montior_SN Montior3_SN
1 Houston d13 1 5 9
2 Houston d18 2 6 10
3 Houston d16 3 7 11
4 Houston d11 4 8 12

I built a union query with the following SQL

SELECT [PC_SN] as Serial
FROM Inv
Union
SELECT [Montior_SN]
FROM Inv
UNION SELECT [Montior3_SN]
FROM Inv;

Which displays as:

Serial
1
2
3
4
5
6

What I am trying to do is add additional fields to my query to display as follows:

Serial Hosting Area
1 d13 Houston
2 d18 Houston
3 d16 Houston
4 d11 Houston
5 d13 Houston
6 d18 Houston

Does anyone know how I may do this?
 

recyan

Registered User.
Local time
Today, 19:09
Joined
Dec 30, 2011
Messages
180
A small question,
Based on the data that you have provided,
I have table with the following fields listed below

Inv ()
ID Area Hosting Pc_SN Montior_SN Montior3_SN
1 Houston d13 1 5 9
2 Houston d18 2 6 10
3 Houston d16 3 7 11
4 Houston d11 4 8 12

and the query used

I built a union query with the following SQL

SELECT [PC_SN] as Serial
FROM Inv
Union
SELECT [Montior_SN]
FROM Inv
UNION SELECT [Montior3_SN]
FROM Inv;

you have shown the result

Which displays as:

Serial
1
2
3
4
5
6

Should this result not be

Serial
1
2
3
4
5
6
7
8
9
10
11
12

Thanks
 

Coldsteel

Registered User.
Local time
Today, 08:39
Joined
Feb 23, 2009
Messages
73
Thanks for the reply, The data does display as

Serial
1
2
3
4
5
6
7
8
9
10
11
12

I just cut it off for the post. Anyone able to help me with issue?
 

MSAccessRookie

AWF VIP
Local time
Today, 09:39
Joined
May 2, 2008
Messages
3,428
The rules for a UNION Query are Simple. Each Subset of the Query must have the same number of the same Type of parameters in the same order. If I understand you correctly, you would need to add two new fields for [Area] and [Hosting], making your Query something like the following:
Code:
SELECT [PC_SN] as Serial, [Area], [Hosting] FROM Inv
UNION 
SELECT [Montior_SN] as Serial, [Area], [Hosting] FROM Inv
UNION 
SELECT [Montior3_SN] as Serial, [Area], [Hosting] FROM Inv;
 

Users who are viewing this thread

Top Bottom