This might be a pretty common query but I'm not really sure how to go about doing it.
My company has a table that identifies doctors and their forms of ID. Because of some faulty load programs, we have an issue where a single doctor may have multiple rows on the table. I'm trying to identify and correct those situations. Here is what the issue looks like:
InternalID
ID1
ID2 Name 1 12345 AA1234 Mike Smith, MD 2 12345 12345 Mike Smith, MD
That second row should not be there but because of the load program, we have millions of rows on our table like that.
So what I would like my query to do is identify all of the rows on the table where there is one row that is correct (InternalID = 1) and one row that is incorrect (InternalID = 2). The eventual goal being to run a job that would delete the incorrect rows. There are millions of rows on the table so optimally the query should probably only return the InternalID of the incorrect rows.
I'd appreciate any ideas you all might have.