Cursussen/Courses Codesnippets     Top 
SQL select - Sort


Sort
It is useful for the user to see the list of records found after a query in alphabetical order.
For this, the statement is extended with the part "order by". You specify the field name (or field names) on which the sort should be performed.
select winery_name, region_id
from winery
where region_id = 5
In the example above you can see that the data is not sorted by "winery_name". The same list is sorted below.
select winery_name, region_id
from winery
where region_id = 5
order by winery_name
If you have multiple field names, you must separate the names with a comma.
You can also sort from largest to smallest or smallest to largest on a numeric field.
select wine_id, on_hand
from inventory
where on_hand > 993
order by on_hand desc
From small to large (or from A to Z) you indicate by putting the word "ASC" (from ascending) after the field names. The word "DESC" (from descending) indicates the opposite. If you don't mention anything "ASC" will be executed.


X

Paragraphs

Sort