ORDER BY
ORDER BY
ORDER BY
.
There is a table "Persons":
| P_Id | LastName | FirstName | Address | City |
|---|---|---|---|---|
| 1 | Hansen | Ola | Timoteivn 10 | Sandnes |
| 2 | Svendson | Tove | Borgvn 23 | Sandnes |
| 3 | Pettersen | Kari | Storgt 20 | Stavanger |
| 4 | Nilsen | Tom | Vingvn 23 | Stavanger |
For this we use this query:
Query Result:
| P_Id | LastName | FirstName | Address | City |
|---|---|---|---|---|
| 1 | Hansen | Ola | Timoteivn 10 | Sandnes |
| 4 | Nilsen | Tom | Vingvn 23 | Stavanger |
| 3 | Pettersen | Kari | Storgt 20 | Stavanger |
| 2 | Svendson | Tove | Borgvn 23 | Sandnes |
For this we use this query:
Query Result:
| P_Id | LastName | FirstName | Address | City |
|---|---|---|---|---|
| 2 | Svendson | Tove | Borgvn 23 | Sandnes |
| 3 | Pettersen | Kari | Storgt 20 | Stavanger |
| 4 | Nilsen | Tom | Vingvn 23 | Stavanger |
| 1 | Hansen | Ola | Timoteivn 10 | Sandnes |






Comments
MySql:
SELECT [column] FROM [table]
ORDER BY RAND()
PostgreSQL:
SELECT [column] FROM [table]
ORDER BY RANDOM()
Microsoft SQL Server:
SELECT [column] FROM [table]
ORDER BY NEWID()
IBM DB2:
SELECT [column], RAND() as IDX
FROM [table]
ORDER BY IDX
Oracle:
SELECT [column] FROM [table]
ORDER BY dbms_random.value Quote
for i:=1 to 5 do
...
select top 3 qwest, them from questions Where them = i ORDER BY newid();
...
in the end we chose three Random matter of fact the first through fifth Quote
And they say that if the basis of a huge number of rows (records) - this is a huge burden when using ORDER BY RAND?
Quote
ie if there is a table of cities, the top result should be the name of non-recurring general and below, respectively, the longest list of cities with the same name! Quote