LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 04-15-2012, 04:25 PM   #1
VijayaRaghavanLakshman
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

col4
aaa
qqq
rrr
xxx
ddd
eee
yyy
ggg

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

Many Thanks,
V
 
Old 04-16-2012, 07:35 AM   #2
GATTACA
Member
 
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, 09:56 AM   #3
VijayaRaghavanLakshman
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.
 
  


Reply



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 04: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 11:48 AM
error unknown column 'xxx' in field list rajesh84210 Linux - Newbie 4 09-07-2009 11:22 PM
selecting particular field/column in file raghu123 Programming 3 08-13-2008 01:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:01 PM.

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