3

I have this table, and i would like a SELECT to exclude the lines marked. The general rule would be:

  • IF there are two or more lines where the controlname AND brandname AND grouptypes columns are equal
  • THEN keep the row where groupname is NOT 'Keine Zuordnung'.
CONTROLNAME BRANDNAME GROUPTYPES GROUPNAME ECU AUDI VERNETZER 1 ECU AUDI VERNETZER Keine zuordnung <--THIS ECU AUDI FUSI Keine zuordnung <--THIS ECU AUDI FUSI 2 ECU2 AUDI FACHANWENDER Keine zuordnung ECU3 AUDI FACHANWENDER Keine zuordnung 

Can i have a little help with this please? Thank you!

4
  • Please post data as formatted text, not images Commented Oct 20, 2016 at 14:41
  • Do you want avoid to SELECT the "duplicate", or do you want to DELETE the "duplicate" from the table? Commented Oct 20, 2016 at 14:56
  • What should be the result (regardless of whether you need "DELETE" or just "SELECT but exclude.") - so, what should be the result if there are duplicate rows like you explained, but ALL the duplicates have 'Keine zuordnung' as GROUPNAME? Delete (or exclude) all of them? Or keep exactly one copy and delete (or exclude) the other(s)? Commented Oct 20, 2016 at 18:26
  • @mathguy All duplicate rows have 'Keine Zuordnung' as GROUPNAME. I need to select only the ones that are duplicate AND their GROUPNAME is NOT 'Keine Zuordnung' + the ones that are not duplicates. Commented Oct 21, 2016 at 4:43

1 Answer 1

4

Here is one method:

select t.* from (select t.*, count(*) over (partition by controlname, brandname, grouptypes) as cnt from t ) t where cnt = 1 or groupname <> 'Keine Zuordnung'; 

It uses a window function to get the count and then a where for your logic.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.