Getting Data from a Domain Using Multiple Attributes

In the previous sections, you queried for items with the attribute Category that contain the value Clothes. This section provides examples of how to write a query using multiple attributes.

The following sample code snippets demonstrate querying for items with the attribute Make that contain the value Audi and the attribute Model that contain the value S4.

Java

To run the sample

  1. Open a clean copy of QuerySample.java.

  2. Remove any comment marks from the invokeQuery(service, request); line and add the following lines after // @TODO: set request parameters here:

    String queryExpression = "['Make' = 'Audi'] intersection ['Model' = 'S4']";
    request.withDomainName("MyStore").withQueryExpression(queryExpression);
  3. Compile and run the sample.

    Amazon SimpleDB returns items with the attribute Make that contain the value Audi and the attribute Model that contain the value S4.

To view the attributes of the returned items, see Getting the Attributes of an Item.

C#

To run the sample

  1. Open AmazonSimpleDBSamples.cs.

  2. Comment out the code you added in the previous section.

  3. Add the following to the Query Action section:

    String queryExpressionMultiAttribute = "['Make' = 'Audi'] intersection ['Model' = 'S4']";
    Query multiAttributeQueryAction = new Query().WithDomainName("MyStore").WithQueryExpression(queryExpressionMultiAttribute);
    
    QuerySample.InvokeQuery(service, multiAttributeQueryAction);
  4. Run the sample.

    Amazon SimpleDB returns items with the attribute Make that contain the value Audi and the attribute Model that contain the value S4.

To view the attributes of the returned items, see Getting the Attributes of an Item.

Perl

To run the sample

  1. Open a clean copy of QuerySample.pl.

  2. Remove any comment marks from the invokeQuery($service, $request); line and add the following lines after the // @TODO: set request parameters here line:

     my $request = Amazon::SimpleDB::Model::Query->new();
     $request->setDomainName('MyStore');
     $request->setQueryExpression("['Make' = 'Audi'] intersection ['Model' = 'S4']");
     
  3. Run the sample.

    Amazon SimpleDB returns items with the attribute Make that contain the value Audi and the attribute Model that contain the value S4.

To view the attributes of the returned items, see Getting the Attributes of an Item.

PHP

To run the sample

  1. Open a clean copy of QuerySample.php.

  2. Remove any comment marks from the invokeQuery($service, $request); line and add the following lines after the // @TODO: set request parameters here line:

    $request = new Amazon_SimpleDB_Model_Query();
    $request->setDomainName('MyStore');
    $request->setQueryExpression('[\'Make\' = \'Audi\'] intersection [\'Model\' = \'S4\']');
    
  3. Run the sample.

    Amazon SimpleDB returns items with the attribute Make that contain the value Audi and the attribute Model that contain the value S4.

To view the attributes of the returned items, see Getting the Attributes of an Item.

VB.NET

To run the sample

  1. Open AmazonSimpleDBSamples.vb.

  2. Comment out the code you added in the previous section.

  3. Add the following to the Query Action section:

    Dim multiAttributeQueryAction As New Query()
    multiAttributeQueryAction.WithDomainName("MyStore").WithQueryExpression("['Make' = 'Audi'] intersection ['Model' = 'S4']")
    
    QuerySample.InvokeQuery(service, multiAttributeQueryAction)
    
  4. Run the sample.

    Amazon SimpleDB returns items with the attribute Make that contain the value Audi and the attribute Model that contain the value S4.

To view the attributes of the returned items, see Getting the Attributes of an Item.

Scratchpad

To run the sample

  1. Open the scratchpad application with a web browser.

  2. Select Query from the Explore API list box.

  3. Enter MyStore in the Domain Name field.

  4. Enter the following in the Query Expression field: ['Make' = 'Audi'] intersection ['Model' = 'S4'].

  5. To limit the number of items returned, enter a value in the Max Number Of Items field.

    If there are more items than you specified in the Max Number Of Items field, Amazon SimpleDB returns a next token.

  6. If you need to view the next page of results, enter the next token in the Next Token field.

    [Note]Note

    To get the next page of results, you only need to specify the domain name and the next token.

  7. Select from the following:

    • To invoke the request, click Invoke Request.

      SDB; returns items with the attribute Make that contain the value Audi and the attribute Model that contain the value S4.

    • To view the signed URL, click Display Signed URL. Then, copy and paste the signed URL into a browser.

      SDB; returns items with the attribute Make that contain the value Audi and the attribute Model that contain the value S4.

    • To view the string to sign, click Display String to Sign.

To view the attributes of the returned items, see Getting the Attributes of an Item.