
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- Updating a MySQL table with values from another table?
- Update multiple values in a table with MySQL IF Statement
- MySQL replace values in a table?
- Replace the empty values from a MySQL table with a specific value
- Select and insert values with preceding zeros in a MySQL table
- Selecting the top occurring entries in MySQL from a table with duplicate values?
- Insert multiple values in a temporary table with a single MySQL query?
- SHOW TABLE statement with multiple LIKE values in MySQL?
- Update all the fields in a table with null or non-null values with MySQL
- Insert values in a table by MySQL SELECT from another table in MySQL?
- How to sum the values in the table by month with MySQL?
- How can we update the values in one MySQL table by using the values of another MySQL table?
- Perform mathematical calculations in a MySQL table with NULL and NON-NULL values
- Insert all the values in a table with a single MySQL query separating records by comma
- Fetch specific rows from a MySQL table with duplicate column values (names)?

Advertisements