MySQL Forums
Forum List  »  Newbie

Re: How can I return column-name?
Posted by: Chris Stubben
Date: July 20, 2005 10:20AM

You probably need to pipe your results to a script and grab the column names and then print each name before the value.

select * from tmp;
+------------+---------------+
| state | city |
+------------+---------------+
| Minnesota | Minneapolis |
| Minnesota | St Paul |
| California | Los Angeles |
| California | San Diego |
| California | San Francisco |
+------------+---------------+


mysql -e 'select * from tmp' test | perl -e '$s=1; while(<>){chomp;if($s){ @c=split /\t/; $s=0;}else{@v=split /\t/; print "$c[0],$v[0],$c[1],$v[1]\n"}}'
state,Minnesota,city,Minneapolis
state,Minnesota,city,St Paul
state,California,city,Los Angeles
state,California,city,San Diego
state,California,city,San Francisco


Chris

Options: ReplyQuote


Subject
Written By
Posted
Re: How can I return column-name?
July 20, 2005 10:20AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.