Reputation: 21351
I have a scraper that stores data into MySQL.
It created columns dynamically as soon a new data field is found.
My table usually ends up having 70-100 columns.
I then export this data using phpMyadmin OR Navicat.
but all columns are not properly arranged and makes it really hard to read.
Is there any way to sort/arrange columns in MySQL?
I know there are some answers posted on SO arranging on column, thats not what I want.
I am also willing to write my own small script to export data into CSV/Excel (using PHPExcel). But I will if I find a way to arrange SELECT
ed data according to column names.
Upvotes: 1
Views: 232
Reputation: 788
You can do this with two separate queries. First one will get all columns of given table
select column_name from information_schema.columns
where table_schema = 'your_schema' and table_name='your_table'
order by column_name
and then use the output as column definition in your select
SELECT implode(', ', $columns) FROM ... (php example)
Upvotes: 2