473,322 Members | 1,522 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,322 software developers and data experts.

Merge Query

GJW
Does anybody know a simply way I can run a query on a single table and
merge the results of several columns of data into a single column of
data?

IE

Table1:

First Name Second Name
------------ ----------------
Fred John
Sue Smith
Ted Jones

Query Result:

Names
--------
Fred
John
Sue
Smith
Ted
Jones

I wouldn't have thought it was a hard thing to do, but I'm getting
nowhere.

Any help would be greatly appreciated.
Nov 13 '05 #1
6 5981
select column1 from yourtable UNION select column2 from yourtable [union
select ... you get the picture]

GJW wrote:
Does anybody know a simply way I can run a query on a single table and
merge the results of several columns of data into a single column of
data?

IE

Table1:

First Name Second Name
------------ ----------------
Fred John
Sue Smith
Ted Jones

Query Result:

Names
--------
Fred
John
Sue
Smith
Ted
Jones

I wouldn't have thought it was a hard thing to do, but I'm getting
nowhere.

Any help would be greatly appreciated.


--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html

Nov 13 '05 #2
open a new query in SQL view and past this into the window:

Select [Table1].[First Name] & " " & [Table1].[Second Name] as [Result]
from [Table1]

Nov 13 '05 #3
GJW
Thanks for the help.

On 27 Jun 2005 05:50:56 -0700, "BillCo" <co**********@gmail.com>
wrote:
open a new query in SQL view and past this into the window:

Select [Table1].[First Name] & " " & [Table1].[Second Name] as [Result]
from [Table1]


Nov 13 '05 #4
GJW
Thanks, this is exactly what I want. I just couldn't think of the SQL
keyword.

On Mon, 27 Jun 2005 13:51:48 +0100, Bas Cost Budde
<b.*********@heuvelqop.nl> wrote:
select column1 from yourtable UNION select column2 from yourtable [union
select ... you get the picture]

GJW wrote:
Does anybody know a simply way I can run a query on a single table and
merge the results of several columns of data into a single column of
data?

IE

Table1:

First Name Second Name
------------ ----------------
Fred John
Sue Smith
Ted Jones

Query Result:

Names
--------
Fred
John
Sue
Smith
Ted
Jones

I wouldn't have thought it was a hard thing to do, but I'm getting
nowhere.

Any help would be greatly appreciated.


Nov 13 '05 #5
GJW schrieb:

Hi GJW,
Does anybody know a simply way I can run a query on a single table and
merge the results of several columns of data into a single column of
data?
jeppers. Want me to tell you? ;-)
IE

Table1:

First Name Second Name
------------ ----------------
Fred John
Sue Smith
Ted Jones

Query Result:

Names
--------
Fred
John
Sue
Smith
Ted
Jones

I wouldn't have thought it was a hard thing to do, but I'm getting
nowhere.
Try using an SQL UNION query.

As long as the number of output fields match, you can stick the results
of two queries one after the other by writing (in SQL query edit mode):

the first query
UNION
the second query;

The queries can even run on different tables.

So, in your case:

SELECT [First Name] AS MyFieldName FROM Table1 (WHERE where clause if
necessary)
UNION
SELECT [Second Name] AS MyFieldName FROM Table1 (WHERE where clause if
necessary);

The 'AS MyFieldName' forces the query to return 'MyFieldName' as Field name.

Any help would be greatly appreciated.


Hope that helped,

Joerg

--

Joerg Glissmann - Guending - Germany
remove PANTS to reply ;-)

Nov 13 '05 #6
For all but the first SELECT, field aliases (AS myfieldname) are
superfluous.

Did you know, by the way, that you can use ORDER BY 3 (if you have at
least three columns, that is)?

Joerg Glissmann wrote:
As long as the number of output fields match, you can stick the results
of two queries one after the other by writing (in SQL query edit mode):

the first query
UNION
the second query;

The queries can even run on different tables.

So, in your case:

SELECT [First Name] AS MyFieldName FROM Table1 (WHERE where clause if
necessary)
UNION
SELECT [Second Name] AS MyFieldName FROM Table1 (WHERE where clause if
necessary);

The 'AS MyFieldName' forces the query to return 'MyFieldName' as Field
name.


--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html

Nov 13 '05 #7

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

Similar topics

2
by: William Wisnieski | last post by:
Hi Everyone, Access 2000 I have some code behind a button that performs a word merge with a query data source. The merge works fine. But what I'd like to do somehow is after the merge is...
1
by: Lisa | last post by:
I have a query named QryDept where one of the fields is DeptID. The query is used for the data source of a mail merge letter. I would like to control which department is to get the mail merge...
8
by: Squirrel | last post by:
Hi everyone, I've created a mail merge Word doc. (using Office XP) , the data source is an Access query. Functionality I'm attempting to set up is: User sets a boolean field to true for...
3
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge...
0
by: Phil C. | last post by:
Hi, I'm using Access 2000. I have a Select Query that uses the MID function to separate the actual text of articles from the title of the articles. The articles are enterd into the...
3
by: cdelarte | last post by:
I would like to be able to mail merge records from multiple mysql tables using a simple template, preferably via a command line script. MSWord mail merge via ODBC will not work for me as it only...
16
by: Sam Durai | last post by:
Hello, I need to merge a small table (of rows less than 100,sometimes even 0 rows) to a big table (of rows around 4 billion). I used the PK of the big table as merge key but merge does a table scan...
1
by: sparks | last post by:
I just got a chance to dl the work and printed out the docs and noticed on one of the screen shots it says print and there is a button for merge all. So this is for single as well as a complete...
2
by: zazu | last post by:
We have a query which is used as a mail merge source in Word. No problem. However we made it a parameter query and when trying to establish the link between the query and the word document in the...
1
by: kayberrie | last post by:
I want to write a VBA mail merge code. I want to link the code/macro/dohicky to a nifty little button so it makes life easy. I think I can handle the button part, the code part - not so much. I know...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.