How to change column names on the fly in mysql?

Hi,

I have a database in which i have required data. I am setting up linnworks and in that i have to do sql queries to get data from the database. The required data is in the database but column names are different than required by linnworks. How do I change column names in the SELECT sql statement so that when data is returned it returns the col names as required by linnworks and not what’s there in database.

Thanks.

Hi Tapan,

You’re in luck :slight_smile: I have recently struggled trying to find a solution using Google and finally arrived at the SQL statement:

“ALTER TABLE master_table_from_csv CHANGE COLUMN OLD_field_name New_field_name VARCHAR(10)”

I discovered that with mysql it is essential to include the field type AND VARCHAR must be all in capitals.

Hi,

Thanks for the solution but I do not want to permanently change the column names. Just when I doing the query they should return the data with the corrosponding temp. col name but permanently they should stay like they are. How to achieve that ?

Thanks.

answer: use column aliases

SELECT nicename1 AS crapname1
     , nicename2 AS crapname2
     , ....

Hi,

Exactly what i wanted.

Thanks.