---
schema_version: "1"
id: 126d548bd62c2cb0cfb1dd77218259f21dc95539cdfc99e45d681841bb39ab1a
title: Sort Example for Orders and Order Items in Amazon DynamoDB
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/dynamodb_qualifiers_sortexample.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.dynamodb_qualifiers_sortexample.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 0b4711cf2b610986075cf6dfa14778f38c57e806cb86b5bd340289f238696df0
description: To effectively sort orders and order items stored in an Amazon DynamoDB table in a way that benefits a business process, create secondary indexes that identify attribute values as the basis for sorting.
products:
  - Salesforce Platform
  - Security
release: "264"
---
# Sort Example for Orders and Order Items in Amazon DynamoDB

To effectively sort orders and order items stored in an Amazon DynamoDB table in a way that benefits a business process, create secondary indexes that identify attribute values as the basis for sorting.

A secondary index allows efficient access to data with attributes other than the primary key values. You can create multiple secondary indexes and give your applications access to different query patterns. A general rule of thumb for creating indexes:

When you query for rows that match condition A, you want to sort the results by attribute B.

A secondary index is a data structure that contains a subset of attributes you select from the table. You must select all the attributes that you want to appear in the query results, even if they’re not used for sorting.

Suppose you want to sort orders for a customer by date, and then sort the line items within an order by quantity. To do this, an Amazon DynamoDB administrator must create specific indexes to support the query and the sort operation:

- `customerID-orderDate-index`: query for the orders for a specific customer (partition key), then sort by date (sort key).
- `orderID-quantity-index`: query for the order items for a specific order (partition key), then sort by quantity (sort key).

If you want to display unit price and any other corresponding details for orders or order items, make sure to include the attributes while you’re creating the index.

#### See Also

- [Qualifier Example for One-to-Many and Many-to-Many Relationships in Amazon DynamoDB](https://help.salesforce.com/s/articleView?id=platform.dynamodb_qualifiers_orderexample.htm&release=264.0.0&type=5 "An enterprise stores and retains fine-grain transaction details for millions of customers, resulting in data volumes reaching billions of records. In this example, Salesforce is the system of record for core customer information and details of all the customer’s orders are stored in Amazon DynamoDB for scale reasons.")
- [Manage Qualifiers for Salesforce Connect Adapter for Amazon DynamoDB](https://help.salesforce.com/s/articleView?id=platform.dynamodb_manage_qualifiers.htm&release=264.0.0&type=5 "Amazon DynamoDB uses unique design patterns to model data efficiently that support multiple table and single table designs. To make data stored in Amazon DynamoDB table accessible to external objects, use qualifiers to reinterpret external data. The qualifiers describe the item attributes and indicates whether an item belongs to the schema represented by the external object. For multiple-table schema designs, the table qualifier is optional.")