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 |
|
aefusco
Starting Member
2 Posts |
Posted - 2012-08-16 : 14:20:23
|
| I have a table that contains records where one field has duplicate values that I don't want to display. Example:Table Name: MyTableFields in MyTable: ID,Name,PolicyNumContent of table:ID - Name - PolicyNum1 - Tony - 12342 - John - 56783 - Mike - 1234Result I am looking for from the SQL: 2 - John - 5678 I've tried all kinds of Counts, Distincts, Group By's, Having, and I cannot seem to get it right! My actual table has many more fields, but the policynum field in the above table is the only field that I don't want to see the records that have duplicate policynums.I greatly appreciate any help, guidance! Tony |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-16 : 14:32:49
|
| [code]SELECT ID,Name,PolicyNumFROM(SELECT COUNT(1) OVER (PARTITION BY PolicyNum) AS Occ,*FROM table)tWHERE Occ=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
aefusco
Starting Member
2 Posts |
Posted - 2012-08-16 : 14:38:26
|
| visakh16 - THANK YOU!!THANK YOU!! THANK YOU!!!!!!!!!!!!I G-R-E-A-T-L-Y APPRECIATE YOUR HELP!!!!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-16 : 14:40:16
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|