Store data in sql for analysis?

Hi folks could please you assist me with this one.

Every time a use shows in results id like to store +1 in MYSQL database to later count how many time some particular user has been shown.

Question.

Is it better to insert a new row each time or insert first time and then update +1 if exists.

I am using mysql db.

P.S. The table uses primary key ID so each row will be given a unique ID which also means

ON DUPLICATE KEY UPDATE

wont work.

Guess that answers your question, now doesn’t it?

But in reality, it depends on what you’re going to do with the data. If you’re just looking for a single count, then a single row with a counter it a better approach. BUT, if you’re looking to do a more granular reporting (like views per month), then you’re going to need a different approach (separate table with something like userID (FK that points to a user record) and date)

OK I hear you brother.

For now I am more interested in simply recording count and then showing the count to the user.

Don’t you think it will generate a ton of data. Imagine ive got 1 mil users and each got 1k views that means:

100 mil rows! Instead by updating we can reduce this to 1 mil.

Like I said in the previous post - it all depends on what you want to do with the data. If you just want a simple count, then yes, a single field on your table will suffice. But if you want to be able to do more granular reporting, then you’ll want a separate table.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.