Database Toolbox |
Use the Order by function to specify the order in which results are sorted.
After selecting Fields in the Visual Query Builder dialog box, click Order by in Advanced query options. The Order By Clauses dialog box appears.
Order By Clauses Dialog Box
1
.
To specify additional fields for sorting, repeat steps 1 through 4. For the Sort key number, type an integer; this specifies that the field will be sorted first, second, etc. If you do not specify the Sort key number, it will have the highest number when added to the Current clauses area. Clauses appear in ascending order by sort key number.
Changes automatically update the Sort key number of the other clauses.
Example Using Order By Clauses
This example retrieves sales volumes for January and February by stock number, and sorts the results first in increasing order for January sales, and then in decreasing order for February sales:
stockNumber
, January
, and February
from the salesVolume
table.
January
, specify the Sort key number to be 1
and for the Sort order, select Ascending; then click Apply. For February
, specify the Sort key number to be 2
and for the Sort order, select Descending; then click Apply (shown below).
1
. Where the values in column 2 are the same (3000
), the values in column 3 (February sales) are in descending order (2400
, 2400
, and 1500
) because the Sort key number specified for February was 2
, and the Sort order was Descending.
Having | SQL Statement or MATLAB Command |
© 1994-2005 The MathWorks, Inc.