Learn how to use SQL SELECT RANDOW rows from a table with the tutorial and Examples. Find out how to retrieve random rows in a table with SQL SELECT RANDOM statement.
You can retrieve random rows from all columns of a table using the (*). Retrieve random rows only from the selected column of the table. You just need to put the column name, table name and the RAND(). See the syntax below to understand the use.
How to Use SQL SELECT RANDOM statement to Retrieve Random Rows
There are many syntaxes given below to get random rows from the table. Many developers using it for exam websites to retrieving random questions from the database.
Many quiz contents need random occurring of questions. To get random questions, you need to use the rand() in SQL SELECT random rows statement.
Syntax1: Select All Column Random Rows.
1 2 3 |
SELECT * FROM tablename ORDER BY RAND(); |
The above syntax select the random from all the columns of a table.
Syntax2: Retrieve Random Rows From Selected Columns in Table.
1 2 3 |
SELECT column_name FROM tablename ORDER BY RAND(); |
The above syntax select random rows only from the specified columns. You just have to enter the column names from which you want to retrieve random rows and the table name from where you want to retrieve the random rows of specified columns.
Parameter Descriptions
Sr.No | Parameter Name | Description |
---|---|---|
1 | column_name | Enter your required column names from where you want to retrieve the random rows. You can also use the symbol (*) to get the random data from all the columns of a table. |
2 | tablename | Specify the table name from which the random data will come. |
1 2 3 |
SELECT Email FROM Employee ORDER BY RAND(); |
1 2 3 |
SELECT * FROM Employee ORDER BY RAND(); |
1 2 3 |
SELECT Name, Email, Mobile FROM Employee ORDER BY RAND(); |
You must also learn.
Reference