SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    564
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,840
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by Tapan View Post
    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 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.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  3. #3
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    564
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,274
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Tapan View Post
    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.
    answer: use column aliases
    Code:
    SELECT nicename1 AS crapname1
         , nicename2 AS crapname2
         , ....
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    564
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    answer: use column aliases
    Code:
    SELECT nicename1 AS crapname1
         , nicename2 AS crapname2
         , ....
    Hi,

    Exactly what i wanted.

    Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •