Finding duplicate mysql record

I’m having trouble with finding mysql duplicate records using PHP. what i want to do is find a duplicate record between two different tables (each have over 1000 records). I decided to place those records into two new database tables, one for the duplicates and another for the records that were not duplicates.
i’ve tried
SELECT table_a.* FROM table_a
LEFT JOIN table_b ON table_a.name = table_b.name
WHERE table_a.name IS NULL
but I keep running into maximum execution time exceeded. I’ve also tried set_time_limit(30); to try and extend it but I still get time outs. any help?

Hello daisuke, set limit in your query as below.(here i put 20 as max limit) SELECT table_a.* FROM table_a LEFT JOIN table_b ON table_a.name = table_b.name WHERE table_a.name IS NULL LIMIT 0, 20

i hope this will helpful for you.
SR

Well the thing is that I wanted to get all records. So I will need to go through all 10,000+ entries in the database lol I guess I could break it up into small increments to do the job. I ended up just setting the time limit to be really high to give it enough time to go through all records. which works. Is there any way to optimize it though? so that I wouldn’t have to set a time limit because i’m sure that the way I went about this query wouldn’t be the most efficient way.

Thank you for your suggestion Sarthak.

Sponsor our Newsletter | Privacy Policy | Terms of Service