sql - remove duplicates/loops from graph data -




i have graph data arcs (consisting of start [s] , end [e]) of graph stored follows in relational table:

if object_id('tempdb..#test') not null drop table #test;  create table #test (     s nvarchar(1)        ,e nvarchar(1) );  insert #test (s, e) values ('a', 'b'); insert #test (s, e) values ('b', 'a'); insert #test (s, e) values ('a', 'c'); 

so graph consists of these arcs:

a -> b b -> a -> c 

i remove duplicates/cycles: -> b , b -> => -> b. possible?

example

;with cte (     select *           ,rn = row_number() on (partition case when s<e s+e else e+s end order s,e)       #test ) delete cte rn>1 

updated test

s   e   b   c 




wiki

Comments

Popular posts from this blog

python - Read npy file directly from S3 StreamingBody -

python - Minimize function with Scipy minimize -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -