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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-08-24 : 23:12:02
|
| Leon writes "I need to be able to retrieve rows of data for one ID and compare it to another of another ID in the same table. Where it dumps rows(of the first set) which are duplicated in the second group.what i have tried is thisSELECT SpeciesHeld.Year, SpeciesTypeCode, FarmedOrHeld, DevelopmentCode FROM SpeciesHeld Where FarmPersonID = '10' and not exists (SELECT SpeciesHeld.Year, SpeciesTypeCode, FarmedOrHeld, DevelopmentCode FROM SpeciesHeld Where FarmPersonID = '2239')I hope you understand this as i'm finding it difficult to explain.So i want to get rid of rows from the outer select which have the same values as the select clauses fields." |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-08-25 : 13:59:56
|
| several ways - easiest probablySELECT SpeciesHeld.Year, SpeciesTypeCode, FarmedOrHeld, DevelopmentCode FROM SpeciesHeld s1 Where FarmPersonID = '10' and not exists (SELECT * from SpeciesHeld s2where s1.SpeciesHeld.Year = s2.SpeciesHeld.Yearand s1.SpeciesTypeCode = s2.SpeciesTypeCodeand s1.FarmedOrHeld = s2.FarmedOrHeldand s1.DevelopmentCode = s2.DevelopmentCodeand s2.FarmPersonID = '2239')==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
Leonus
Starting Member
1 Post |
Posted - 2002-08-28 : 04:46:57
|
| Thanks nr that worked great |
 |
|
|
|
|
|