select start,end from
(
select start,end from table1
union all select end,start from table1
) group by start,end having count(start)>1

解决方案 »

  1.   

    测试:create table #aa(id int,start varchar(10),[end] varchar(10))
    insert #aa values(1,'aaa','bbb')
    insert #aa values(2,'aaa','bbb')
    insert #aa values(3,'bbb','aaa')
    insert #aa values(4,'aa','bb')
    insert #aa values(5,'aa','bb')
    insert #aa values(6,'a','bbb')
    insert #aa values(1,'bb','aa')
    select start,[end] from
    (
    select start,[end] from #aa
    union all select [end],start from #aa
    ) emp group by start,[end] having count(start)>1----------------------------------------------
    start      end        
    ---------- ---------- 
    bb         aa
    bbb        aaa
    aa         bb
    aaa        bbb(4 row(s) affected)
      

  2.   

    稍改一下
    select start,end from
    (
    select start,end from table1
    union all select end,start from table1
    ) aa  -- 给一个别名
    group by start,end having count(*)>1
      

  3.   

    declare @start varchar(50) 
    declare @end  varchar(50)
    DECLARE zxg_cursor CURSOR FOR 
    SELECT start,end
    FROM table1 OPEN zxg_cursor 
    FETCH NEXT FROM authors_cursor 
    INTO @start, @end
    WHILE @@FETCH_STATUS = 0
       BEGIN
              select  * from  table1 where (start=@start and end=@end) or (start=@end  and end=@start)          FETCH NEXT FROM titles_cursor INTO @start,@end   
       END   CLOSE zxg_cursor 
       DEALLOCATE zxg_cursor 
      

  4.   

    ---这样就行了!·你可以参考我上面的测试数据进行测试
    select start,[end] from
    (
    select start,[end] from yourtable
    union all select [end],start from yourtable
    ) emp group by start,[end] having count(start)>1