I have a large table with more than 200,000 rows that I only need to check the last few thousand rows for duplicates (not all) before I insert a new row into. Currently I'm running this query for each row I want to add:
SELECT ID from table where date='' and time=''
And based on the response from that query I write the row if the response is empty.
The issue I have with doing this is that it takes a very long time, and as the database grows this only increases how long it takes.
I tried using LIMIT and OFFSET
by saying SELECT ID from table where date='' and time='' limit 200000,18446744073709551615
which I thought would only search through rows after 200,000 to the end of the database however running this query doesn't seem to be any faster.
My question is this: Is there a more efficient way to "skip ahead" in the database and only search a portion of the rows instead of all of the rows?