View Full Version : Moving rows in a table

11-07-2011, 08:35 AM
When I execute;

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 |

11-07-2011, 09:06 AM
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.

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.

11-07-2011, 09:42 AM
So, is it possible to move the column "D" over?

11-07-2011, 03:21 PM
get yourself a decent editor. Heidi sql foinstance lets you drag & drop column.

11-07-2011, 03:35 PM

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

11-07-2011, 03:42 PM
yes it is:

D varchar(10)

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.

11-07-2011, 03:56 PM
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.

Old Pedant
11-07-2011, 09:28 PM
I could be wrong, but I think all he really wanted was to do this:

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

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.

11-08-2011, 12:29 PM
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.

11-08-2011, 01:10 PM
guelphdad, you have too much time on your hands.

Old Pedant
11-08-2011, 07:30 PM
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.

11-08-2011, 08:39 PM
you should have the courtesy

You'll be waiting a while, if ever, to see anything remotely close from that one.

11-09-2011, 01:07 AM
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.

Old Pedant
11-09-2011, 01:46 AM
??? 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.

11-09-2011, 01:48 AM
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.

11-09-2011, 10:36 AM
It worked guelphdad, thanks.


11-09-2011, 05:12 PM
.... your bull **** accusations.

Chill man, go and read: http://www.codingforums.com/rules.htm

You are violating very first rule.

11-10-2011, 01:20 AM
BubikolRamios, having enough time on hand to to try and act like the forum police when you are not even a moderator is disturbing. I urgently urge you to seek counselling!