Support the ongoing development of →
Laravel Database Eloquent
Last updated 2 years ago.

Rather than looping over every item in the DB, can you run a select query to check for duplicates? I don't know exactly what you're trying to compare, but something like this might do the trick:


@Ben Sampson , I have to insert new user to the table which contains 5 million records. I have to check whether this new user is already present in table or not. If not, then insert user else update his rating.


Ok, I would approach it by looping over each new user to be added (can't tell if you're adding just 1 or more than 1 user at a time). You can run a select query to see if they exist in the table already, if they do, update them. If they don't then insert them.


@Ben Sampson,Thanks. will approach as same as you.


Sign in to participate in this thread!


Your banner here too?

DPS dps Joined 30 May 2018


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.