I have a table from which I need to select all persons who have a first name that is not unique, and that this set should only be selected if, among persons with a similar name, everyone has a different surname.
Example:
FirstN LastN
Bill Clinton
Bill Cosby
Bill Maher
Elvis Presley
Elvis Presley
Largo Winch
I want to receive
FirstN LastN
Bill Clinton
or
FirstN LastN
Bill Clinton
Bill Cosby
Bill Maher
I tried this, but it does not return what I want.
SELECT * FROM Ids
GROUP BY FirstN, LastN
HAVING (COUNT(FirstN)>1 AND COUNT(LastN)=1))
[Edited my post after remark by Alard P. Lovesefer]
source
share