---
title: "SQL SERVER order by random in series"  
description: "SQL SERVER order by random in series"  
author: "Steilla Mitchel"  
published: 2023-07-30  
updated: 2023-07-31  
canonical: https://www.mindstick.com/forum/159369/sql-server-order-by-random-in-series  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# SQL SERVER order by random in series

[SQL SERVER](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server) [order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience) by [random](https://www.mindstick.com/forum/33419/generating-random-numbers-in-objective-c) in [series](https://answers.mindstick.com/qa/101432/what-s-the-highest-score-in-a-single-world-series-game)

## Replies

### Reply by Aryan Kumar

Sure, here is how to order by random in series in [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) [Server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over):

SQL

```plaintext
USE MyDatabase;

SELECT CustomerID, FirstName, LastName
FROM Customers
ORDER BY NEWID();
```

The `NEWID()` function returns a unique identifier, which is a random number that is guaranteed to be unique. The `ORDER BY` clause orders the rows by the `NEWID()` function, which will sort the rows in a random order.

The `NEWID()` function is a database-specific function, so it may not be available in all databases. If the `NEWID()` function is not available, you can use the `RAND()` function, which returns a pseudo-random number.

The following query is equivalent to the previous query, but it uses the `RAND()` function instead of the `NEWID()` function:

SQL

```plaintext
USE MyDatabase;

SELECT CustomerID, FirstName, LastName
FROM Customers
ORDER BY RAND();
```

The `RAND()` function is not guaranteed to be unique, so it is possible that the rows will be sorted in the same order every time the query is executed. If you need to ensure that the rows are sorted in a different order every time the query is executed, you can use the `NEWID()` function.


---

Original Source: https://www.mindstick.com/forum/159369/sql-server-order-by-random-in-series

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
