change order of fields using phpMyAdmin

Schuyler Kuhl
Schuyler Kuhl used Ask the Experts™
on
Greetings,

Is there a way to change the order of the fields using phpMyAdmin?

Or is it better to delete the field and re-add it where I want it.

I don't think it matters, the order of the fields but just for neatness I'd like to have related things together.

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Not sure if phpMyAdmin has a built-in method, but I believe you can use ALTER TABLE to do it:

ALTER TABLE your_table MODIFY COLUMN field_to_move VARCHAR(123) AFTER other_field;

That should put "field_to_move" after the the field called "other_field" - you may not need the column definition (VARCHAR(123)), either. Try it on a test table without the column definition and see if it works. If it doesn't, you'll need to pass the corect column definition, INT/VARCHAR/whatever
Reza RadConsultant, Trainer
Commented:
if you want to fetch them through a query, just change the order,  i mean :
select field1,field2 from table1

but if you mean change order in table structure, the only way is remove and add fields again
Reza RadConsultant, Trainer

Commented:
of course when i said the only way, i mean in visual gui of phpmyadmin
if you want command way, do @gr8gonzo recommendation

Author

Commented:
Thank you!
I don't think you can reorder the fields in mysql, you will have to delete and recreate the fields in the order you want them, if you have data in the table you may want to export the database (structure and data) and re-organize the sql file appropriately.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial