What SQL returns duplicates in first column where values in 2nd column differ?
问题 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 回答1: SELECT id, origin FROM My_Table T1 WHERE EXISTS (SELECT * FROM My_Table