title: Fetching items from dynamoDB with sorting
body: <p>In my project i want to fetch all records from table with sort by <strong>created_date</strong> descending order. 
  Also i want to add condition of fetch all item not <strong>created_by</strong> login user.
  I have tried many ways but not able to achieve it.</p>
  
  <p>Below is my table structure.
  <a href="https://i.stack.imgur.com/oJYG8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oJYG8.png" alt="dynamodb table structure"></a></p>
  
  <p>Here is my java code to fetch records from dynamoDB.</p>
  
  <pre><code>Map&lt;String, Condition&gt; filter = new HashMap&lt;String, Condition&gt;();
  //filter.put(RealmConstant.Expo.created_by, new Condition().withComparisonOperator(ComparisonOperator.NE).withAttributeValueList(new AttributeValue().withS(userId)));
  filter.put(RealmConstant.Expo.created_date, new Condition().withComparisonOperator(ComparisonOperator.LE.toString()).withAttributeValueList(new AttributeValue().withS(""+new Date())));
  
  Expo expo =new Expo();
  expo.setCreated_by(userId);
  
  DynamoDBQueryExpression&lt;Expo&gt; queryExpression = new DynamoDBQueryExpression&lt;Expo&gt;();
  queryExpression.setHashKeyValues(expo);
  queryExpression.setIndexName(AppConstant.DynamoDBTableIndex.created_by_created_date_index);
  queryExpression.setConsistentRead(false);
  queryExpression.setRangeKeyConditions(filter);
  
  queryExpression.setScanIndexForward(false);
  return mapper.query(Expo.class, queryExpression);
  </code></pre>
  
  <p>As per above code i am getting all records created by me only. I want to fetch all records not created by me.</p>
  
  <p>Also tried <code>.withFilterExpression("created_by &lt;&gt; :val1").withExpressionAttributeValues(eav);</code> but not working. As already question posted. <a href="https://stackoverflow.com/questions/44998093/why-is-there-no-not-equal-comparison-in-dynamodb-queries">Why is there no **not equal** comparison in DynamoDB queries?</a></p>
  
  <p>and</p>
  
  <p><a href="https://stackoverflow.com/questions/41646098/dynamodb-filter-expression-can-only-contain-non-primary-key-attributes?rq=1">DynamoDB: Filter Expression can only contain non-primary key attributes</a></p>