Question is very similiar to this find duplicates but I'd like to find only those duplicate id with code different than 'ROME' and at least one name is 'ROME'.
I want desired results because:
1. ID is duplicate.
2. At least one origin is 'ROME'
3. Remaining rows for that ID are NOT 'ROME'
Table
ID ORIGIN
-----------
1 ROME
1 ROME
2 ROME
2 LODI
3 ASTI
4 PISA
4 BARI
Desired Results
ID ORIGIN
-----------
2 ROME
2 LODI
Output
2 Rome
2 Lodi
This produced the results you're looking for. I'm not sure if it has any errors for a different data set. But this should get you going in the right direction.
It was asked in a comment if this could be written more generically. It cannot, otherwise we would not get the correct results (PISA and BARI would trip the WHERE on Table1.Origin != Table2.Origin)