Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MarcTroesken's avatar

How would you guys do that ?

Hey guys,

I am aggregating sales data for analytics and write that into another database for later visualization. So here's the thing:

I'm thinking about the concept how to insert/update that data every night. There are 2 ways in my opinion:

  1. Get/Aggregate data (e.g. all from 2018), then loop over it and search for existing entries - update them - or insert because its a new one (Con: slow)

or

  1. Get/Aggregate data (e.g. all from 2018), then drop all 2018 data from db and insert the new ones. (Con: high index count)

The thing is that data can change. An entry inserted yesterday may be changes tomorrow and needs to be updated/inserted again in the next cycle.

So how would you guys go for that ? Any ideas or advises ?

Thanks Marc

0 likes
4 replies
lostdreamer_nl's avatar

How about using upsert? ( Mysql way: insert into ... values (...) on duplicate key UPDATE )

Setup the unique keys on the table correctly, and upsert the data in there.

MarcTroesken's avatar

yeah thats an option. But there is no query builder method for this right ? I guess im ending up writing it raw.

Please or to participate in this conversation.