Many times, duplicate data exists in tables that we would rather ignore. So, doing a SELECT for example would return the duplicate data, when in fact that would be a bit of a problem for us.
One way to get around this is to get MySQL to ignore the duplicate records, which can be done with the command
ALTER IGNORE TABLE testtable ADD UNIQUE INDEX(col1,col2);
What this does is creates an index on two columns in the table, getting unique rows for that index, and ignoring any additional rows that match. This won’t check the entire table for a match, but only those two columns, so it might leave out useful rows if you are not careful with which columns you select in the index.
If all is working as it should, the resulting queries on this table should return back the data, excluding duplicates.
Related posts:
- Matrices in C# Matrices are a very useful thing in computer programming –...
- Using MySQL from Visual Studio.NET Visual Studio.NET is very geared to being paired up with...
- Writing an exchange rate graph in PHP – Part one: Getting the data Over the next few blog posts I am going to...
- Writing an exchange rate graph in PHP – Part four: The finishing touches Now that we have everything in place, it would be...
- Combinations, permutations and factorials in C# Factorials are defined as a number that is multiplied by...
Related posts brought to you by Yet Another Related Posts Plugin.
Serge Meunier is a software developer living in Cape Town, South Africa. He loves programming, fencing, philosophy, feeding his internet addiction, and, of course, dogs.
Comments