Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-15-2012, 05:25 PM   #1
LQ Newbie
Registered: Jan 2012
Posts: 10

Rep: Reputation: Disabled
How to display 2 different column field values as one column value in mysql

Hi All,

Am trying to display/select 2 column filed values under single coulmn. ie,

If i have table with 3 columns and 4 rows, i would like to select/display col1 and col3 values and display there values as single column values.

Example :

col1 col2 col3
aaa sss ddd
qqq www eee
rrr ttt yyy
xxx fff ggg

now from the above table, i would like to display col1/col3 values as single col4 ie, output should look like


i tried with UNION and CONCAT but no luck. could anyone please tell me how to do this using mysql query.

Many Thanks,
Old 04-16-2012, 08:35 AM   #2
Registered: Feb 2002
Location: USA
Distribution: Fedora, CENTOS
Posts: 209

Rep: Reputation: 32
I'm not sure what you mean. Do you want to concatenate the two columns together? Or do you want to *append* col3 to col1?

For concatenation:
SELECT CONCAT(col1,col3) as newCol_ FROM table_name

You may have to cast the data in col1 or col3 to varchar depending upon the datatype they are (your posting is a little short on details).

Fro the second case, you'll have to create a new table (a temporary one should suffice) and dump you col1 and col3 data there sequentially.
Old 04-16-2012, 10:56 AM   #3
LQ Newbie
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thanks GATTACA. I looking for the second solution which you have mentioned.

Need to append col3 values under col1

I don't know how to do it without creating tmp table.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
compare second column of a file then print the first column of it in a ne fil if true java_girl Linux - Newbie 2 03-16-2012 05:50 AM
how to sort the 2nd column on the basis of first column without repeating the value ? zediok Linux - Newbie 15 12-20-2011 12:48 PM
error unknown column 'xxx' in field list rajesh84210 Linux - Newbie 4 09-08-2009 12:22 AM
selecting particular field/column in file raghu123 Programming 3 08-13-2008 02:31 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:44 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration