The result from your query is just messy. It reports A, B, java and B, A, java.
declare @J table (uid int, sid int, primary key (uid, sid));
insert into @J values
(1, 1)
, (1, 2)
, (1, 7)
, (2, 1)
, (2, 6)
, (3, 1)
, (3, 2);
declare @N table (id int primary key, name varchar(10));
insert into @N values
(1, 'bob')
, (2, 'ted')
, (3, 'mac');
select j1.sid, n1.name, n2.name
from @J j1
join @J j2
on j2.sid = j1.sid
and j2.uid <> j1.uid
join @N n1
on n1.id = j1.uid
join @N n2
on n2.id = j2.uid
order by j1.sid, j1.uid, j2.uid;
sid name name
1 bob ted
1 bob mac
1 ted bob
1 ted mac
1 mac bob
1 mac ted
2 bob mac
2 mac bob
< > a > , , 2 .
select j1.sid, n1.name, n2.name
from @J j1
join @J j2
on j2.sid = j1.sid
and j2.uid > j1.uid
join @N n1
on n1.id = j1.uid
join @N n2
on n2.id = j2.uid
order by j1.sid, j1.uid, j2.uid;
sid name name
----------- ---------- ----------
1 bob ted
1 bob mac
1 ted mac
2 bob mac
select *
from ( select j1.sid, n1.name
, count(*) over (partition by j1.sid) as cnt
from @J j1
join @N n1
on n1.id = j1.uid
) t
where t.cnt > 1
order by t.sid, t.name;
sid name cnt
1 bob 3
1 mac 3
1 ted 3
2 bob 2
2 mac 2