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.
My table and rows as follows,t1c1 c2 c3---------------------------------------------------BCTAN2RM BCTAN2SC30RM 20081016BCTAN2RM TBC2SPORESUN30RM 20081016BCTANRM BCTANSC30RM 20081016BCTANRM TBCSPORESUNSC30RM 20081016DEFAULTRM DEFAULT2RM 20080101DEFAULTRM DEFAULT30BP2RM 20090608DEFAULTRM DEFAULT30BPRM 20090608DEFAULTRM DEFAULT30BPSUNRM 20090608INETRM INETSATRM 20090812INETRM INETSUNDAYRM 20090812How to Select Distinct and the resultset as follow,c1 c2 c3---------------------------------------------------BCTAN2RM BCTAN2SC30RM 20081016BCTANRM BCTANSC30RM 20081016DEFAULTRM DEFAULT30BP2RM 20090608INETRM INETSUNDAYRM 20090812I dont care the value of c2 and c3 (randomly pickup is ok). Me only care c1 is not repeated.
singularity
Posting Yak Master
153 Posts
Posted - 2010-02-06 : 21:20:54
Here's one way:
select c1, c2, c3from(select c1, c2, c3, row_number() over (partition by c1 order by newid()) as rnfrom t1) awhere rn = 1