By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,208 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Merge Query

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.