Re: How can I return column-name?
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