Skip to content
Advertisement

sql duplicates within duplicates

Having a hard time wording my issue. But finding duplicates within duplicates is about as close as i can get without an example.

  • ID is the id of the row.
  • stringA,stringB are just arbitrary strings.
  • dID,oID are FK relationship to other tables.

I am trying to create a query that will give me all the rows where oID is 1 and dID is not unique and where stringA OR stringB is not unique. When finding not unique values for stringA and stringB the rows need to have matching dID for that comparison. If the dID does not match, we don’t care about those duplicates.

My expected query against the above dataset above would return nothing. Because there is no row where dID is not unique but also has not unique values for stringA or stringB.

My expected query against this given dataset would return both row 1 and 4. Because their oID and dID match and stringA matches.

I have tried using nested selects using having count(*) > 1 on the fields but it keeps returning row 1 from the first dataset.

Any help is appreciated, thanks!


Corrected the result set.

Added more clarity to condition.


I thought this really ugly query was working, but turns out it is not working fully.

Advertisement

Answer

I found a solution that worked for now.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement