SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2003
    Location
    GMT+5
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Field order and time

    HI,

    1. How to change the order of the fields (together with the values) in one table from A|B|C|D to A|D|B|C ?

    2. How to copy one field from one table to another table?

    2. How to change the values of a field which previously use unixstamp to datetime. Is there any script or easy way to do that as i have about 1300 rows to change.

    Thanks for your help

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. The columns in your table? use the necessary order in your select query

    2.
    Code:
    INSERT INTO table2 (column2) AS SELECT column1 FROM table1;
    3. You first have to change that field to the appropriate column type (don't know if it is automatically converted if you change it from int to datetime. if so, use an additional step with varchar(30) and the datetime)

    Try something like:

    Code:
    UPDATE yourtable SET datecolumn = FROM_UNIXTIME(datecolumn, '%Y-%m-%d %H:%i:%s');
    Better use a backup before running that query.

  3. #3
    SitePoint Member
    Join Date
    Feb 2003
    Location
    GMT+5
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Chris82
    1. The columns in your table? use the necessary order in your select query
    There a lot to change in script, so I prefer just change the order of the columns in the mysql database.

    Any idea?

    Thanks

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    hmmm, sounds like a homework assignment, but if it is not, then i suggest you do not need to change the order of the columns in the table -- but if you really want to do it, then you have to drop the table and recreate it

    what did you mean by "copy one field from one table to another table" -- can you give an example?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Member
    Join Date
    Feb 2003
    Location
    GMT+5
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937
    i suggest you do not need to change the order of the columns in the table -- but if you really want to do it, then you have to drop the table and recreate it
    All the coloumns already have values.

    I am thinking just like in excel, we move (by cut) a column and then paste whereever I want in the same sheet.

    Any idea?


    Quote Originally Posted by r937
    what did you mean by "copy one field from one table to another table" -- can you give an example?
    Sorry If I was not so clear. I want to copy a coloumn (together with all values) in table A to table B.

    In excel, we copy a coloumn in sheet A, and paste it in sheet B

    Any idea?

    Thanks

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i don't know what to say

    a database is not a spreadsheet

    if you want to see the columns in order A, C, D, then when you write the query, you write SELECT A, C, D, in that order

    as for moving a column from one table to another, this too is pretty tricky

    why don't you re-arrange your data in excel? sounds like you're more comfortable there

    once you have the data exactly the way you want it, then import it into your database


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
  •