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
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. To change this behavior, use the every()
operator to
return results where every attribute matches the query expression.
This section shows queries on attributes with multiple values and their results.
Note
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.
Select Expression | Description | Result |
---|---|---|
select * from mydomain where 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 |
select * from mydomain where Keyword = 'Book' and Keyword = 'Hardcover' |
Retrieve all items that have the Keyword attribute as both "Book" and "Hardcover." Based on the data set, 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 |
<none> |
select * from mydomain where every(keyword) in ('Book', 'Paperback') |
Retrieves all items where the only keyword is Book or Paperback. If the item contains any other keyword entries, it is not returned. |
0385333498, 0802131786 |