0

I have an products table that contains 160,000 products. The problem is their order, they are ordered by their insertion time. For summary I want to completely shuffle them and save them into the DB in the new order, What will be the easiest way to do that ?

Summary of the reason: all of my products right now are sectioned by their category (E.G from id 1000 to 2000 all the products are red dressed and from 2000 to 3000 all the products are white boots). I have an feed of products, now the problem is when i display the feed its boring (display many shoes then many dresses). my main goal here is to make my feed more interesting and varied

R.Bar
  • 362
  • 1
  • 16
  • 1
    **[edit]** your question and add some sample data and the expected output based on that data. [**Formatted text**](http://stackoverflow.com/help/formatting) please, [no screen shots](http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557) –  Jan 05 '17 at 13:42
  • 1
    you can use order by random() – danielarend Jan 05 '17 at 13:48
  • i just edit my question, please take a look again. (summary - i want to save them into the db in the new order) – R.Bar Jan 05 '17 at 14:20
  • What's the purpose of changing their order in the DB? What perceived problem are you trying to solve? – Dave Newton Jan 05 '17 at 14:21
  • 1
    "*and save them into the DB in the new order*" - rows in a relational database have no order –  Jan 05 '17 at 14:22
  • Hey Dave, all of my products right now are sectioned by their category (E.G from id 1000 to 2000 all the products are red dressed and from 2000 to 3000 all the products are white boots). I have an feed of products, now the problem is when i display the feed its boring (display many shoes then many dresses). my main goal here is to make my feed more interesting and varied – R.Bar Jan 05 '17 at 14:25
  • a_horse_with_no_name - My meaning here is the rising column and the primary key or as we all know it : the ID. – R.Bar Jan 05 '17 at 14:27
  • 1
    You don't impose order on the storage of records, you impose order on records as they're read from the database. "shuffle and write them to the DB in the new order" is an impossible, nonsensical task. What you're after is a query that orders randomly. – user229044 Jan 05 '17 at 14:52
  • You should never use IDs as a logical ordering or grouping system. You say IDs 1000 - 2000 are red dresses but what happens when you add another red dress? It's going to be ID 160,001. Really it's best to just forget you even have an primary ID column. – Dan Jan 06 '17 at 17:26

0 Answers0