Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Moving rows in a table

    When I execute;
    Code:
    select * from alphabet;
    I get the rows:
    | A | B | D | C |
    Is it possible to move the column "D" over, so I get:
    | A | B | C | D |
    ?

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts
    This will switch the contence of D and C column. doh they will be named the same as before, so if you want to rename do it + that.
    Code:
    update alphabet
    set D = @a:=D,D = C, C = @a;
    But be careful, make backup. If duplicate key vioation apears, or something, during execution, I don't guarantee anything.
    Last edited by BubikolRamios; 11-07-2011 at 09:09 AM.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    So, is it possible to move the column "D" over?

  • #4
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts
    get yourself a decent editor. Heidi sql foinstance lets you drag & drop column.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    Thanks.

    Is it possible to move the column "D" over from the MySQL terminal interface?

  • #6
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    yes it is:

    Code:
    ALTER TABLE 
      alphabet
    CHANGE
      D
      D varchar(10) 
    AFTER
      C
    the D or whatever column name it actually is, is listed the first time to specify the column

    you then specify the column and column definition in the next line (doesn't have to be VARCHAR(10) for example)

    and then tell it what column to go after.

  • #7
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    Cool. Thanks, guelphdad.

    I am about to goto bed, but I will use this command tomorrow and let you know how it went.

    Take care.

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    I could be wrong, but I think all he really wanted was to do this:
    Code:
    SELECT A, B, C, D from table
    In other words, just change the order *IN THE SELECT*.

    Why actually move the fields around? That might make sense for the current SELECT.

    But maybe tomorrow you will want to have a query that does
    Code:
    SELECT D, B, E from table
    You wouldn't go around altering the order of the fields each time you needed a different order in your SELECT.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    asked and answered on another forum, sounded there that the column switch was permanent for some reason.

    And of course the thread title in both places is incorrect as we're talking about moving/switching the order of columns and nothing to do with rows.

  • #10
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    guelphdad, you have too much time on your hands.

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    When you post in multiple forums, you should have the courtesy to say so and provide a link to the other thread. That way we don't waste our time answering when you already have an answer.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #12
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by Old Pedant View Post
    you should have the courtesy
    You'll be waiting a while, if ever, to see anything remotely close from that one.

  • #13
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    When you post in multiple forums, you should have the courtesy to say so and provide a link to the other thread. That way we don't waste our time answering when you already have an answer.
    For someone who is old, I am suprized you have not yet learn't to not assume in life in circumstances where you accuse people, because when you fail, it makes you look like a fool.

    I just looked the the last 8 threads I made. Only 1 has not been marked as solved - because I forgot.
    Some have the answer - which is probably solved (like this one), but I have not had the time to getting around tackling that problem, but as history shows, I some times come back days later to simply say it has been solved.

    Therefor, 95% of the time I say solved (on this forum).. so drop your bull **** accusations.
    Last edited by FlashDance; 11-09-2011 at 01:49 AM.

  • #14
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    ??? There was no accusation in there.

    There was a statement of fact: It *is* courteous to tell people you are posting in other forums. And I'm not talking about marking as "resolved". I mean at the time you make the post. Marking resolved is great, but it doesn't help the case where you get an answer but don't see it until tomorrow, yet 4 hours later in the other forum somebody makes the same long answer to you. Doesn't apply in this case. Nobody spent 30 minutes answering you. But it can matter in many question/answer sessions.

    It was my impression that I had helped you several times in the past. And you said thanks, and all went well. But if you prefer I keep my nose out of your threads, so be it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #15
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    Whilst I wait for a response for help (after exhausting my own attempt looking on search engines), I move on to doing the next task set out in my "todo" folder. This usually leads to encountering other problems along the way which sets me back more. This can some times set me back a day or two from tackling my previous problem on que (such as this one), which is why I return a day or two later to mark solved or what ever... my todo folder is quite big. lol

    I have 5 things to do on que before I can return to tackling this problem.

    The Little Guy on the other forum provided the solution after guelphdad, and as I believe the answer he gave is correct, I marked it as solved. If his answer was wrong, it will make no difference. That thread will die away into the internet never to be seen again. I only marked solved on the other forum out of respect for The Little Guy.

    Although I am sure guelphdad's solution is correct, I have not tried and tested it.. but he did provide the solution first, so this is my marking point.
    Last edited by FlashDance; 11-09-2011 at 02:17 AM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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