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 4116898
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:46:03+00:00 2026-05-20T22:46:03+00:00

I want to store last 5 days stats for a user in database. I

  • 0

I want to store last 5 days stats for a user in database. I have two types of db table design in my mind.

Design 1:

id      user_name   stats
1        Peter       54             //Day 1 stats for Peter
2         Peter       50             //Day 2 stats for Peter
3         Abc         10             //Day 1 stats for Abc
4         Peter       55             //Day 3 stats for Peter
5         Abc         14             //Day 2 stats for Abc.

Design 2:

id  user_name   day1    day2    day3    day4   day5
1    Peter       54      50      55       -      -
2     Abc        10      14       -       -      -

Which of the above two is better ?
Since I want stats for only last 5 days, thats why I want to overwrite the oldest day stats when adding new day so that at any time there are maximum 5 days stats for the user.
Please tell me how that should be done.

  • 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-05-20T22:46:04+00:00Added an answer on May 20, 2026 at 10:46 pm

    Design 1 is far superior. If you decide you want to record more days in future, you don’t want to have to write another set of queries to get to this data. I presume you meant to have a ‘day’ column in Design 1? Why not have a DateTime field to indicate the day like so:

    id    user_name      day           stats
    1     Peter          31-Mar-2011   54
    2     Peter          01-Apr-2011   24
    3     Abc            01-Apr-2011   23
    

    Then you can purge the data at your own convenience. The id primary key field is simply to simplify row identification when used in queries / updates.

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

Sidebar

Related Questions

I have a php site. I want to store an last ip for each
I want to store my users clicks from the last 10 days in my
I have the following array I want to store in my database... $insData =
I am a new developer on Android and I want store user data in
I want to store a large number of sound files in a database, but
I want to store a large result set from database in memory. Every record
Okay, I have a list of URLs in a MySQL table. I want the
I want to store more than 1000 character in database, I use MySQL database.
For my spotify application i want to store images of artists from last.fm temporaily
I want to store only last 200 data (if 201 data is coming means

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.