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--]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.