Share via


Accessing Records in Descending Order

You can view records in descending order by creating a descending index, or by reading an existing index in descending order.

To create a descending index

  • In the Index tab of the Table Designer, choose the arrow button to the left of the Name box so that the arrow points down.

    -or-

  • Use the DESCENDING clause with the INDEX ON command to create a descending index.

To create a compound structural index file, you can use either method. To create other types of index files, you can use the second method. For example, you could create a new descending index ordering your product table from highest to lowest unit_price and browse the table in the new order with the following code:

USE products
INDEX ON unit_price TAG unit_price DESCENDING
BROWSE

To read an existing index in descending order

  • Use the DESCENDING clause of the SET ORDER command to read an existing index in descending order.

Reading an existing index in descending order enables you to leverage an existing index rather than create a new one. For example, you may have already created an index ordering your product table by unit_price with the following code:

USE products
INDEX ON unit_price TAG unit_price

By default, the order is ascending. You could browse the table in descending order with the following code:

USE products
SET ORDER TO unit_price DESCENDING
BROWSE

The previous examples focus on accessing information in descending order. Both the SET ORDER and INDEX commands also offer an ASCENDING clause. You can combine these two commands to gain tremendous flexibility in your application. For example, if you use the ASCENDING or DESCENDING clause to create an index in the most frequently used order, you can then use the opposite clause with the SET ORDER command to view or access the information in the opposite order, when that order is more convenient.

See Also

Index Creation Based on Expressions | Filtering Data | Working with Records | Table Designer | Creating One Index | Creating Multiple Indexes | Ordering by Multiple Fields | Index Creation for Tables