Not adding duplicates ?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Death
Forum Newbie
Posts: 17
Joined: Tue Apr 19, 2005 11:52 am

Not adding duplicates ?

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Try selecting from the table where TEXT='text' first... if any rows are returned then it's already there ;)
Death
Forum Newbie
Posts: 17
Joined: Tue Apr 19, 2005 11:52 am

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

lookup what UNIQUE can do for you..
R0d Longfella
Forum Newbie
Posts: 20
Joined: Fri Apr 08, 2005 7:17 am

Post by R0d Longfella »

You can create an index for any column in MySQL. Indexes speed up a select query.
Post Reply