E-mail Print PDF

ORDER BY

ORDER BY

ORDER BY

.

1
2
3
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) |

There is a table "Persons":

P_IdLastNameFirstNameAddressCity
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:

1
2
SELECT * FROM Persons
ORDER BY LastName

Query Result:

P_IdLastNameFirstNameAddressCity
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:

1
2
SELECT * FROM Persons
ORDER BY LastName 

Query Result:

P_IdLastNameFirstNameAddressCity
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

 
+16 #1 Betmen 2010-02-24 19:37 Unknown method of sorting a random (Random)

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
 
 
0 #2 Игорь 2010-08-31 05:19 and the meaning is in the randomization task if the query to sort and organize? Quote
 
 
+4 #3 Betmen 2010-09-04 23:27 Igor, there is! I took it when I wrote testilku and I had heaps of those, each lot of questions, choose three (five, that does not matter) with luchaynyh question of each topic for the "general" test. Here we take in SQL:
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
 
 
-1 #4 Azat 2010-11-09 23:43 Tell me how to specify in the ORDER BY RAND () I have the desired number of entries.
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
 
 
-1 #5 jura4x01 2011-01-12 19:41 How to create a query that will select all of the table data, but will sort them by Ascending Number of repetitions Name?
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
 
 
+1 #6 oo7 2011-03-25 22:11 Can you please tell how to make a request to apartment numbers were in ascending order, but the problem is that there are apartments with drive letter (eg 127a) Quote
 

Authorization

Nice Ajax Poll

Which one of my extensions is the best?

Statistics

Translate

русскийitalianoDeutschEnglishLATVIANукраїнськаfrançaispolski
1

Advertisement