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 |
|
venkath
Posting Yak Master
202 Posts |
Posted - 2007-02-22 : 12:40:43
|
| Hi allI have a query ...select CONTRACT_SITE_ID, FAMILY, CONTRACT_PARTY_TYPE_CODE, count(*)from CONTRACT_PARTY group by CONTRACT_SITE_ID, FAMILY, CONTRACT_PARTY_TYPE_CODEhaving count(*) = 2output:10000403127 INVBN BILL 210000403127 INVBN DELCO 210000403127 INVBN FUFIL 210000410422 REVSR BILL 210000410422 REVSR DELCO 210000410422 REVSR FUFIL 2The table contract_party has a primary key column CONTRACT_PARTY_ID,Now i need a query to delete one of the two records (Remove the one with smaller CONTRACT_PARTY_ID) that matches the above criteria.Thanks.. |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-02-22 : 12:58:02
|
Try this and if it is giving the required output, you can convert it to DELETE. Remember, this SELECT will give you the records which you need to delete.Select t1.*From CONTRACT_PARTY t1JOIN (Select CONTRACT_SITE_ID, Max(CONTRACT_PARTY_ID) as CONTRACT_PARTY_ID From CONTRACT_PARTY Group by CONTRACT_SITE_ID) t2on t1.CONTRACT_SITE_ID = t2.CONTRACT_SITE_IDand t1.CONTRACT_PARTY_ID < t2.CONTRACT_PARTY_ID Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|
|