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.
| Author |
Topic |
|
DKV
Starting Member
5 Posts |
Posted - 2010-08-04 : 14:41:16
|
| I have data like thisTable A:RecID CaseNum AID Cat11 case1 111 Normal2 case2 222 Abnormal3 case3 333 Failure4 case2 222 Normal5 case4 444 Abnormal6 case5 555 Failure7 case6 666 Normal8 case4 444 Abnormal9 case3 333 FailureI want to move rows with with unique CaseNum in table B, irrespective of what is in AID and Cat1 columns, so that table B looks like this:Table B:RecID CaseNum AID Cat11 case1 111 Normal2 case2 222 Abnormal3 case3 333 Failure5 case4 444 Abnormal6 case5 555 Failure7 case6 666 NormalWhat is the best way to achieve that?Thanks for your help. |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-08-04 : 15:53:43
|
| [code]SELECT RecID,CaseNum,AID,Cat1 FROM(SELECT row_number() over(partition by CaseNum order by RecID) as seq, * from TableA) tWHERE t.seq = 1[/code] |
 |
|
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2010-08-04 : 15:55:03
|
| SELECT MIN(recid),casenum,aid,cat1 FROM tablename GROUP BY casenum,aid,cat1Mike"oh, that monkey is going to pay" |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-08-04 : 15:59:25
|
quote: Originally posted by mfemenel SELECT MIN(recid),casenum,aid,cat1 FROM tablename GROUP BY casenum,aid,cat1Mike"oh, that monkey is going to pay"
Mike..I don't think this will work for that sample data as the values for Cat1 are different for the same CaseNum. |
 |
|
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2010-08-04 : 16:10:52
|
| ah, dang. Missed that one with the difft value.Mike"oh, that monkey is going to pay" |
 |
|
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2010-08-04 : 16:27:52
|
| ok. we'll try that againSELECT base.RecID, base.casenum, base.aid,cat1FROM #temp tINNER JOIN (SELECT MIN(t.RecID)RecID ,CaseNum ,AID FROM #temp t GROUP BY CaseNum ,AID )baseon t.recid=base.recidMike"oh, that monkey is going to pay" |
 |
|
|
|
|
|
|
|