There was a bug in code that was creating duplicate rows. Here is a sample of two of the columns in my table as it looked before I removed the duplicates. (there is an identity column, ID
and other columns that are irrelevant)
SampleID ProjectID
0 c0f5e4cc-7664-4d70-ab3f-6ff832aa8ece
0 c0f5e4cc-7664-4d70-ab3f-6ff832aa8ece
0 c0f5e4cc-7664-4d70-ab3f-6ff832aa8ece
0 c0f5e4cc-7664-4d70-ab3f-6ff832aa8ece
1 c0f5e4cc-7664-4d70-ab3f-6ff832aa8ece
1 c0f5e4cc-7664-4d70-ab3f-6ff832aa8ece
1 c0f5e4cc-7664-4d70-ab3f-6ff832aa8ece
1 c0f5e4cc-7664-4d70-ab3f-6ff832aa8ece
1 c0f5e4cc-7664-4d70-ab3f-6ff832aa8ece
1 c0f5e4cc-7664-4d70-ab3f-6ff832aa8ece
0 00e95061-96e2-4db5-999e-5ca629561c50
0 00e95061-96e2-4db5-999e-5ca629561c50
0 00e95061-96e2-4db5-999e-5ca629561c50
1 00e95061-96e2-4db5-999e-5ca629561c50
1 00e95061-96e2-4db5-999e-5ca629561c50
1 00e95061-96e2-4db5-999e-5ca629561c50
1 00e95061-96e2-4db5-999e-5ca629561c50
1 00e95061-96e2-4db5-999e-5ca629561c50
I needed to remove duplicates from the table so that I am left with a table with these rows, and was eventually to accomplish this, but my question is why the query that I originally tried didn't work as expected.
SampleID ProjectID
0 c0f5e4cc-7664-4d70-ab3f-6ff832aa8ece
1 c0f5e4cc-7664-4d70-ab3f-6ff832aa8ece
0 00e95061-96e2-4db5-999e-5ca629561c50
1 00e95061-96e2-4db5-999e-5ca629561c50
The query that I tried is
DELETE FROM INS_Sample WHERE ID NOT IN
(SELECT MIN(ID) FROM INS_Sample GROUP BY SampleID, ProjectID);
and I found it in an answer to this question. When I ran this query, it seemed to running indefinitely so I stopped it and the query had actually been inserting more duplicate rows into my table. I had to run SELECT MIN(ID) FROM INS_Sample GROUP BY SampleID, ProjectID
first and make a comma seperated list of the resulting ID
s to paste into my original query so that it looked like this
DELETE FROM INS_Sample WHERE ID NOT IN
(1234, 5678, /*a lot more IDs*/);
before I could get the results I want. Why doesn't my first query work as it should, and how in the world were rows getting inserted into the table? There isn't anything else in my query editor other than a select to see what is in the table.