I would like to create a column that increments each time the same value is found in the first column. These fields could be strings, or integers. Something like:
field1 | field2
cat | 1
fish | 1
dog | 1
cat | 2
fish | 2
cow | 1
My question is similar to these two (1), (2), but I do not want to INSERT
or UPDATE
if the key already exists. I want to delete the second record. So, something like DELETE FROM t1 WHERE field2 > 1
.
This question (MySQL delete duplicate records but keep latest) is MOST similar to what I'm trying to do, except instead of having an integer auto-incremented ID column, I have another field called filename
, which would be different for each repeated field1.
Is this called an aggregate function? How to accomplish this?