Page 1 of 1
Can I change row order in MySQL Database?
Posted: Sun Jun 19, 2011 4:55 am
by nyo
Hi,
I have a simple MySQL database and I am working on it through phpMyAdmin. I have a couple of rows and I was wondering if it is possible to change the order of the rows.
Thanks.
Re: Can I change row order in MySQL Database?
Posted: Sun Jun 19, 2011 9:57 am
by libeco
In what way? When selecting? Or just the id?
Re: Can I change row order in MySQL Database?
Posted: Sun Jun 19, 2011 11:30 am
by jacek
By default the rows are ordered by the ID so to reorder them you can change that.
Re: Can I change row order in MySQL Database?
Posted: Sun Jun 19, 2011 3:26 pm
by nyo
Well, the table has 5 rows in the following order now:
ID
content
title
name
date
So, can I change this order to have something like:
ID
title
name
content
date
without deleting and recreating them? Not so important but just wondering.
Re: Can I change row order in MySQL Database?
Posted: Sun Jun 19, 2011 3:47 pm
by jacek
Those are columns ... and as far as I know there is no war to change the order
Re: Can I change row order in MySQL Database?
Posted: Sun Jun 19, 2011 3:53 pm
by libeco
Download HeidiSQL (assuming you're using Windows). It's a free database management application (I use it a lot and really like it). It supports re-ordering columns.
Re: Can I change row order in MySQL Database?
Posted: Sun Jun 19, 2011 4:07 pm
by nyo
jacek wrote:Those are columns ... and as far as I know there is no war to change the order
Sorry, my bad, I should say columns and thanks for your opinion.
libeco, thanks for the suggestion, never heard of that application before but it seems nice. I will definitely try it on my localhost, but my hosting account has phpmyadmin and I have to use it.
Re: Can I change row order in MySQL Database?
Posted: Sun Jun 19, 2011 4:11 pm
by libeco
phpmyadmin is just an interface. If your host supports remote connections you can still use HeidiSQL.
Re: Can I change row order in MySQL Database?
Posted: Mon Jun 20, 2011 6:26 am
by nyo
libeco wrote:phpmyadmin is just an interface. If your host supports remote connections you can still use HeidiSQL.
I downloaded HeidiSQL and using it on localhost. Do you know how to import a database? It has "Import > Load SQL File" option but that doesn't import the database to my local mysql server.
Re: Can I change row order in MySQL Database?
Posted: Mon Jun 20, 2011 11:12 am
by libeco
If you hit the Execute SQL (F9) button it will execute the SQL.
Re: Can I change row order in MySQL Database?
Posted: Mon Jun 20, 2011 1:13 pm
by nyo
libeco wrote:If you hit the Execute SQL (F9) button it will execute the SQL.
Thank you libeco, it's ok now. But it seems it doesn't directly import a database. It requires a database to be created and selected so that it can import the SQL query and populate the database.
Re: Can I change row order in MySQL Database?
Posted: Mon Jun 20, 2011 4:49 pm
by libeco
I tested it this afternoon and it worked for me. Make sure there's a create statement if you want the database created. Here's my test script if you want to try:
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `test123`
--
CREATE DATABASE `test123` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `test123`;
CREATE TABLE `bla` (
`asd` varchar(5) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Re: Can I change row order in MySQL Database?
Posted: Tue Aug 23, 2011 8:24 pm
by shahzadkb
Databases do not store data in any particular order, it is up to you to write your select statements in such a way the the data is retrieved in the order you want.