create table #tbl1(a nvarchar(max)) insert into #tbl1 va...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

create table #tbl1(a nvarchar(max))
insert into  #tbl1 values
('1'),('2'),('3'),('4')
 
 
 
create table #tbl2(b nvarchar(max))
insert into  #tbl2 values
('a'),('b'),('c'),('d')


 select * from(
select #tbl1.a ,#tbl2.b   ,row_number() over 
(partition by #tbl1.a order by #tbl2.b)  rn  from #tbl1,#tbl2 
 ) fff where rn=1

--SELECT unique_ID , s.f FROM #tbl1 cross apply(select top  1 unique_ID as f from #tbl2) s

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results