select * from  friend a
where exists(select 1 from friend b
where a.u_id=b.friend_id and a.friend_id=b.U_id)

解决方案 »

  1.   

    Create table friend(U_id int,friend_id int)
    insert into friend select 1,3
    insert into friend select 2,3
    insert into friend select 3,2select U_id,friend_id as 好友 from  friend a
    where exists(select 1 from friend b
    where a.u_id=b.friend_id and a.friend_id=b.U_id)
    and U_id=3select U_id,friend_id  as 审核好友 from  friend a
    where not  exists(select 1 from friend b
    where a.u_id=b.friend_id and a.friend_id=b.U_id)
    and friend_id=3
      

  2.   

    select *
    from ta a
    where not exists(select 1 from ta where Friend_ID = a.Friend_ID and U_ID = a.U_ID) 
          and U_ID = 3