Page 1 of 1
Not adding duplicates ?
Posted: Sat Jun 25, 2005 5:36 pm
by Death
Hi guys,
My table rows look like this: (INT,INT,TEXT). I want to make sure I don't insert a row where the TEXT field matches one already in there.
Is there an easy way to do that ?
Thank you.
Posted: Sat Jun 25, 2005 5:56 pm
by Chris Corbyn
Try selecting from the table where TEXT='text' first... if any rows are returned then it's already there

Posted: Sat Jun 25, 2005 6:56 pm
by Death
Hi,
Is there a more efficient way ? If my table has 10,000 rows that's 10,000 string comparisons per insert statement. If I insert 100 new rows that's 1,000,000 string comparisons, it will be slow. I guess it has to be done that way but maybe MySQL has internal optimizations to handle something like that.
Thanks.
Posted: Sun Jun 26, 2005 5:01 am
by timvw
lookup what UNIQUE can do for you..
Posted: Sun Jun 26, 2005 1:10 pm
by R0d Longfella
You can create an index for any column in MySQL. Indexes speed up a select query.