SQL SELECT RANDOM
The SQL SELECT RANDOM statement is used to retrieve a random row from a table. It is useful when you want to pick a random record for testing or sampling purposes.
Syntax
The basic syntax for SELECT RANDOM is:
SELECT RANDOM column_name
FROM table_name;
Example
We will retrieve a random product from the Orders table.
Code Example
-- Select a random product ordered
SELECT RANDOM Product FROM Orders;
Output
Phone
Explanation
- The query selects a random product from the Orders table.
- Each time the query is run, it will return a different result based on randomness.