Jump to content
Sign in to follow this  
karl Jonson

Check duplicates in TADOQuery

Recommended Posts

I have this procedure:

procedure FindDuplicate(Qry : TADOQuery);

The Qry contains just 1 column: "Codes"
Which the most efficient way to check that "Codes" column doesn't contain any duplicates ?

TIA

Share this post


Link to post

What is the metric for efficiency? You would have to iterate the query and for every record check the value in a memory structure if it's there you have duplicate if not insert into it.

 

You can store the list in an array, list or a hash table.

  • Like 1

Share this post


Link to post
22 hours ago, karl Jonson said:

I have this procedure:


procedure FindDuplicate(Qry : TADOQuery);

The Qry contains just 1 column: "Codes"
Which the most efficient way to check that "Codes" column doesn't contain any duplicates ?

TIA

Modify the SELECT statement for the query to include an ORDER BY clause for the code column. Then you can walk over the query result and just compare the current record's code to the one from the previous record (which you remember in a local variable in the loop).

You can also formulate a SELECT statement that just returns the duplicates of course...

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×