Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have two results setsSelect a,b,c from table1this result has only distinct values of column a.and Select a,d,e,f from table2this result has duplicate values for column a.I need two join the two results on the column a but eliminate the duplicates in the second table.Select * from(Select a,b,c from table1) r1inner join (Select a,d,e,f from table2)r2on r1.a=distinct(r2.a)How can I get distinct out of table 2.
BendJoe
Posting Yak Master
128 Posts
Posted - 2010-04-29 : 18:16:52
Anybody have a solution.
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2010-04-29 : 21:27:37
if you are using SQL 2005/2008, you can use the row_number() to get that.
select *from ( select a,d,e,f, row_no = row_number() over (partition by a order by d,e,f) from table2 ) t2where t2.row_no = 1