 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Reshuffle the values in a table with MySQL
To reshuffle the values in a table, use MySQL RAND().
Let us first create a table −
mysql> create table DemoTable792 ( Name varchar(100), Subject varchar(100) ); Query OK, 0 rows affected (0.66 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable792 values('Chris','MySQL'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable792 values('David','MySQL'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable792 values('Robert','MongoDB'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable792 values('Carol','MongoDB'); Query OK, 1 row affected (0.18 sec) Display all records from the table using select statement −
mysql> select *from DemoTable792;
This will produce the following output -
+--------+---------+ | Name | Subject | +--------+---------+ | Chris | MySQL | | David | MySQL | | Robert | MongoDB | | Carol | MongoDB | +--------+---------+ 4 rows in set (0.00 sec)
Following is the query to reshuffle the values in a table −
mysql> select *from DemoTable792 order by rand();
This will produce the following output -
+--------+---------+ | Name | Subject | +--------+---------+ | Chris | MySQL | | Robert | MongoDB | | David | MySQL | | Carol | MongoDB | +--------+---------+ 4 rows in set (0.00 sec)
Advertisements
 