Jump to content

change database entry order


tucker

Recommended Posts

you cannot shift the order physically in a table, but you could select the items in random order

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * FROM yourtable ORDER BY rand() [!--sql2--][/div][!--sql3--]

If you really need to physically change the orders, you'll have to create a temporary table that has the same properties as the first table. Then you can insert data from the first table into the temporary table, select a row to be moved in the first table, and update the other row (the row that you put into the temporary table) with the information from the selected row. Now select your row from the temporary table, and update the row in the first table that you "moved". If that's too complicated to read, this may help:

 

Let FTable be first table and TTable be temp. table

We will switch rows 2 and 6.

Row 2 from FTable gets copied into TTable.

Row 6 in FTable overwrites Row2 in FTable (select then update)

Row 2 from TTable overwrites Row 6 in FTable (select then update)

TTable is deleted.

End result: row 2 and row 6 are switched.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.