Queries on Attributes with Multiple Values

One of the unique features of Amazon SimpleDB is that it allows you to associate multiple values with a single attribute. Internet-related attributes such as "tag" or "keyword" often contain multiple values, which are easy to support through the Amazon SimpleDB data model and query language.

[Important]Important

Each attribute is considered individually against the comparison conditions defined in the predicate. Item names are selected if any of the values match the predicate condition.

This section shows queries on attributes with multiple values and their results. To view the source data for the queries, see Sample Query Data Set.

The following table shows some queries on attributes with multiple values, how they are interpreted, and the results they return from the sample dataset.

Query ExpressionDescriptionResult
['Rating' = '4 stars' or 'Rating' = '****']

Retrieves all items with a 4 star (****) rating

The data set has this rating stored as both "4 stars" and "****." Amazon SimpleDB returns items that have either or both.

1579124585, 0802131786, B000T9886K
['Keyword' = 'Book' and 'Keyword' = 'Hardcover']

Retrieve all items that have Keyword attribute as both "Book" and "Hardcover"

You might be surprised that the result did not return the "1579124585" item. As described earlier, each value is evaluated individually against the predicate expression. Since neither of the values satisfies both comparisons defined in the predicate, the item name is not selected.

To get the desired results, you can use the ['Keyword' = 'Book'] intersection ['Keyword' = 'Hardcover'] query expression. For more information, see Multiple Attribute Queries.

<none>