What about:
"ALTER TABLE <tablename>
ORDER BY <fieldname>;"

HTH, Cor


----- Original Message ----- From: "Rob Wultsch" <[EMAIL PROTECTED]>
To: "afan pasalic" <[EMAIL PROTECTED]>
Cc: <mysql@lists.mysql.com>
Sent: Thursday, May 15, 2008 8:23 PM
Subject: Re: reorder records in database


On Thu, May 15, 2008 at 11:38 AM, afan pasalic <[EMAIL PROTECTED]> wrote:
is there built in function to "reset" order_no or I have to create php
script for it?

There is not a built in way to do this. Using a user defined variable
it is not all that hard to deal with though

mysql> drop table if exists t1;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE `t1` (
   ->   `col1` int,
   ->   `col2` int
   -> );
Query OK, 0 rows affected (0.03 sec)

mysql> insert into t1 values(0,1),(3,2),(5,3),(7,4),(9,5),(11,6),(15,7);
Query OK, 7 rows affected (0.00 sec)
Records: 7  Duplicates: 0  Warnings: 0

mysql>
mysql> SET @incr =0;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> UPDATE t1
   -> SET col1 =(SELECT @incr:[EMAIL PROTECTED])
   -> ORDER BY col1;
Query OK, 7 rows affected (0.00 sec)
Rows matched: 7  Changed: 7  Warnings: 0

mysql>
mysql> select * from t1;
+------+------+
| col1 | col2 |
+------+------+
|    1 |    1 |
|    2 |    2 |
|    3 |    3 |
|    4 |    4 |
|    5 |    5 |
|    6 |    6 |
|    7 |    7 |
+------+------+
7 rows in set (0.00 sec)


--
Rob Wultsch
[EMAIL PROTECTED]
wultsch (aim)

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]





--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to