A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Union query, combine all 4 fields into 1 field



 
 
Thread Tools Display Modes
  #1  
Old July 4th, 2009, 09:38 PM posted to microsoft.public.access.queries
efandango
external usenet poster
 
Posts: 489
Default Union query, combine all 4 fields into 1 field

I have a union query:

SELECT

tbl_Points.Run_No,
tbl_Points.LeaveBy1,
tbl_Points.LeaveBy2,
tbl_Points.LeaveBy3,
tbl_Points.LeaveBy4

FROM tbl_Points

UNION ALL SELECT
tbl_Points.Run_No,
tbl_Points.LeaveBy1,
tbl_Points.LeaveBy2,
tbl_Points.LeaveBy3,
tbl_Points.LeaveBy4,
FROM tbl_Points;


the results give me:

Run_No Field1 Field2 Field3 Field4
1 data data data date
2 data data data date
3 data data data date
and so on....

How can I get my union to merge field1,2, 3 and 4 into 1 consecutive column,
like this:

Run_No Field
1 data
1 data
1 data
1 data
2 data
2 data
2 data
2 data
3 data
3 data
3 data
3 data
....
  #2  
Old July 4th, 2009, 11:27 PM posted to microsoft.public.access.queries
Duane Hookom
external usenet poster
 
Posts: 7,177
Default Union query, combine all 4 fields into 1 field

Your union looks like your SELECTs are the same. What's up with that? What's
the name of your union query?

Try something like;
SELECT Run_No, Field1 as FLD
FROM quniQuery
UNION ALL
SELECT Run_No, Field2
FROM quniQuery
UNION ALL
SELECT Run_No, Field3
FROM quniQuery
UNION ALL
SELECT Run_No, Field4
FROM quniQuery;

--
Duane Hookom
Microsoft Access MVP


"efandango" wrote:

I have a union query:

SELECT

tbl_Points.Run_No,
tbl_Points.LeaveBy1,
tbl_Points.LeaveBy2,
tbl_Points.LeaveBy3,
tbl_Points.LeaveBy4

FROM tbl_Points

UNION ALL SELECT
tbl_Points.Run_No,
tbl_Points.LeaveBy1,
tbl_Points.LeaveBy2,
tbl_Points.LeaveBy3,
tbl_Points.LeaveBy4,
FROM tbl_Points;


the results give me:

Run_No Field1 Field2 Field3 Field4
1 data data data date
2 data data data date
3 data data data date
and so on....

How can I get my union to merge field1,2, 3 and 4 into 1 consecutive column,
like this:

Run_No Field
1 data
1 data
1 data
1 data
2 data
2 data
2 data
2 data
3 data
3 data
3 data
3 data
...

  #3  
Old July 5th, 2009, 01:34 AM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 2,364
Default Union query, combine all 4 fields into 1 field

I think you want something more like

SELECT Run_No, LeaveBy1 as LeaveBy
FROM tbl_points
UNION ALL
SELECT Run_No, LeaveBy2
FROM tbl_points
UNION ALL
SELECT Run_No, LeaveBy3
FROM tbl_points
UNION ALL
SELECT Run_No, LeaveBy4
FROM tbl_points
UNION ALL

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


efandango wrote:
I have a union query:

SELECT

tbl_Points.Run_No,
tbl_Points.LeaveBy1,
tbl_Points.LeaveBy2,
tbl_Points.LeaveBy3,
tbl_Points.LeaveBy4

FROM tbl_Points

UNION ALL SELECT
tbl_Points.Run_No,
tbl_Points.LeaveBy1,
tbl_Points.LeaveBy2,
tbl_Points.LeaveBy3,
tbl_Points.LeaveBy4,
FROM tbl_Points;


the results give me:

Run_No Field1 Field2 Field3 Field4
1 data data data date
2 data data data date
3 data data data date
and so on....

How can I get my union to merge field1,2, 3 and 4 into 1 consecutive column,
like this:

Run_No Field
1 data
1 data
1 data
1 data
2 data
2 data
2 data
2 data
3 data
3 data
3 data
3 data
...

  #4  
Old July 5th, 2009, 12:24 PM posted to microsoft.public.access.queries
efandango
external usenet poster
 
Posts: 489
Default Union query, combine all 4 fields into 1 field

thanks Wayne, this worked:

SELECT Run_No, LeaveBy1 as FLD
FROM tbl_Points;
UNION ALL
SELECT Run_No, LeaveBy2
FROM tbl_Points;
UNION ALL
SELECT Run_No, LeaveBy3
FROM tbl_Points;
UNION ALL
SELECT Run_No, LeaveBy4
FROM tbl_Points;

but what did you mean "...looks like your SELECTs are the same"?



"Duane Hookom" wrote:

Your union looks like your SELECTs are the same. What's up with that? What's
the name of your union query?

Try something like;
SELECT Run_No, Field1 as FLD
FROM quniQuery
UNION ALL
SELECT Run_No, Field2
FROM quniQuery
UNION ALL
SELECT Run_No, Field3
FROM quniQuery
UNION ALL
SELECT Run_No, Field4
FROM quniQuery;

--
Duane Hookom
Microsoft Access MVP


"efandango" wrote:

I have a union query:

SELECT

tbl_Points.Run_No,
tbl_Points.LeaveBy1,
tbl_Points.LeaveBy2,
tbl_Points.LeaveBy3,
tbl_Points.LeaveBy4

FROM tbl_Points

UNION ALL SELECT
tbl_Points.Run_No,
tbl_Points.LeaveBy1,
tbl_Points.LeaveBy2,
tbl_Points.LeaveBy3,
tbl_Points.LeaveBy4,
FROM tbl_Points;


the results give me:

Run_No Field1 Field2 Field3 Field4
1 data data data date
2 data data data date
3 data data data date
and so on....

How can I get my union to merge field1,2, 3 and 4 into 1 consecutive column,
like this:

Run_No Field
1 data
1 data
1 data
1 data
2 data
2 data
2 data
2 data
3 data
3 data
3 data
3 data
...

  #5  
Old July 5th, 2009, 12:26 PM posted to microsoft.public.access.queries
efandango
external usenet poster
 
Posts: 489
Default Union query, combine all 4 fields into 1 field

Thanks John,

Your's worked after I removed the very last line:

'UNION ALL' (which was giving an incomplete Query clause' error.


"John Spencer" wrote:

I think you want something more like



my SQL:

SELECT Run_No, LeaveBy1 as LeaveBy
FROM tbl_points;
UNION ALL
SELECT Run_No, LeaveBy2
FROM tbl_points;
UNION ALL
SELECT Run_No, LeaveBy3
FROM tbl_points;
UNION ALL
SELECT Run_No, LeaveBy4
FROM tbl_points;








SELECT Run_No, LeaveBy1 as LeaveBy
FROM tbl_points
UNION ALL
SELECT Run_No, LeaveBy2
FROM tbl_points
UNION ALL
SELECT Run_No, LeaveBy3
FROM tbl_points
UNION ALL
SELECT Run_No, LeaveBy4
FROM tbl_points
UNION ALL

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


efandango wrote:
I have a union query:

SELECT

tbl_Points.Run_No,
tbl_Points.LeaveBy1,
tbl_Points.LeaveBy2,
tbl_Points.LeaveBy3,
tbl_Points.LeaveBy4

FROM tbl_Points

UNION ALL SELECT
tbl_Points.Run_No,
tbl_Points.LeaveBy1,
tbl_Points.LeaveBy2,
tbl_Points.LeaveBy3,
tbl_Points.LeaveBy4,
FROM tbl_Points;


the results give me:

Run_No Field1 Field2 Field3 Field4
1 data data data date
2 data data data date
3 data data data date
and so on....

How can I get my union to merge field1,2, 3 and 4 into 1 consecutive column,
like this:

Run_No Field
1 data
1 data
1 data
1 data
2 data
2 data
2 data
2 data
3 data
3 data
3 data
3 data
...


  #6  
Old July 5th, 2009, 01:59 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 2,364
Default Union query, combine all 4 fields into 1 field

Sorry about that. The perils of copy and paste struck.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


efandango wrote:
Thanks John,

Your's worked after I removed the very last line:

'UNION ALL' (which was giving an incomplete Query clause' error.


"John Spencer" wrote:

I think you want something more like



my SQL:

SELECT Run_No, LeaveBy1 as LeaveBy
FROM tbl_points;
UNION ALL
SELECT Run_No, LeaveBy2
FROM tbl_points;
UNION ALL
SELECT Run_No, LeaveBy3
FROM tbl_points;
UNION ALL
SELECT Run_No, LeaveBy4
FROM tbl_points;







SELECT Run_No, LeaveBy1 as LeaveBy
FROM tbl_points
UNION ALL
SELECT Run_No, LeaveBy2
FROM tbl_points
UNION ALL
SELECT Run_No, LeaveBy3
FROM tbl_points
UNION ALL
SELECT Run_No, LeaveBy4
FROM tbl_points
UNION ALL

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


efandango wrote:
I have a union query:

SELECT

tbl_Points.Run_No,
tbl_Points.LeaveBy1,
tbl_Points.LeaveBy2,
tbl_Points.LeaveBy3,
tbl_Points.LeaveBy4

FROM tbl_Points

UNION ALL SELECT
tbl_Points.Run_No,
tbl_Points.LeaveBy1,
tbl_Points.LeaveBy2,
tbl_Points.LeaveBy3,
tbl_Points.LeaveBy4,
FROM tbl_Points;


the results give me:

Run_No Field1 Field2 Field3 Field4
1 data data data date
2 data data data date
3 data data data date
and so on....

How can I get my union to merge field1,2, 3 and 4 into 1 consecutive column,
like this:

Run_No Field
1 data
1 data
1 data
1 data
2 data
2 data
2 data
2 data
3 data
3 data
3 data
3 data
...

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:16 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.