Postgres Identifying 2 records with 1 attribute equal and 1 attribute not equal
This could be a way:

select
    ID
from
    t t1
where exists (select 1
              from   t t2
              where  t2.A = t1.A
                     and t2.B &lt;&gt; t1.B)
order by
    ID;


It could be read as: Give me all ID's if exists another row with same A and different B.



| id |
| -: |
|  1 |
|  2 |
|  3 |
|  4 |
|  5 |



db&lt;>fiddle here