Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8788603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:11:07+00:00 2026-06-13T22:11:07+00:00

I need help with querying a DynamoDB table to get the count of rows.

  • 0

I need help with querying a DynamoDB table to get the count of rows.

Consider, I have a table “Users” with three fields, “UserName”, “Password” and “UserType”. UserType can be “Admin”, “Employee” or @”Guest”. Now I want to get the count of “Admin” in the table. In SQL we write the query like this,

SELECT COUNT(*) FROM Users WHERE UserType='Admin'

Now I need to do the same using DynamoDB iOS SDK. For now, I am doing it like this.

- (int)adminUsersCount {
    DynamoDBScanRequest *request = [[[DynamoDBScanRequest alloc] initWithTableName:@"Users"] autorelease];
    DynamoDBCondition *condition = [[[DynamoDBCondition alloc] init] autorelease];
    NSMutableArray *attrList = [NSMutableArray arrayWithObject:[[[DynamoDBAttributeValue alloc] initWithS:@"Admin"]] autorelease]];
    condition.attributeValueList = attrList;
    condition.comparisonOperator = @"EQ";
    [request setScanFilterValue:condition forKey:@"UserType"];
    DynamoDBScanResponse *response = [[AmazonClientManager ddb] scan:request];
    return response.items.count;
}

Here I am fetching all the rows to know that count. I know this is not the right way and is really a bad idea. I don’t know how to get the count alone without fetching all the rows.

  1. I want to know how to do it in iOS SDK.
  2. I want to know how to do it in PHP SDK as well.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:11:08+00:00Added an answer on June 13, 2026 at 10:11 pm

    I can not answer for PHP nor IOS SDK since I use neither of them (I use Python). But, from a low level DynamoDB point of view:

    • If all users are admin, you can use ItemCount from DescribeTable. It is updated only every 6 hours but it’s free
    • If UserType is the range_key (excelent), you can set Count param of Query to True then read Count field of the answer.
    • In all other cases (bad), use Scan as you would with Query along with your filter condition.

    This said, Query and Scan will always return the the item count. The Count param only instruct them not to return the real items. Please note that it only spares bandwidth. It won’t be any faster nor be cheaper in terms of provisioned throughput.

    If you are in the 3rd case, I suggest you re-engineer your you schema as it would be very slow and expensive. At all requests, you will need to go through the entire table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need help with a query that I wrote: I have three tables Company id
need help/guide for sql select query, I have 2 table stock and stock_history, in
need help in error in database pivot. i have table tamed table_score like below:
I need help querying the friendID from a table. My table stores the user
Need some help with Activerecord Querying in a has_many :through association. Model: Job class
need help regarding USSD Gateway. I have to develop an app, which will directly
I have a problem in querying phonebook contacts. What I need to do is
I hope someone can help me out. I have a table that logs our
any body can help me please? i want to querying from my table, the
I need help writing a T-SQL query that will generate 52 rows of data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.