Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eliminating Records from a Query based on a Condition 1

Status
Not open for further replies.

LeonelSanchezJr

Programmer
Jan 26, 2001
522
US
If the query returns 3 records for the same Document #, then I want to keep the 3 records in the result set.

However, if the query returns less than 3 records for the
same Document #, then I want to delete the records from my result set (which is in a Temp Table). B-)

DOCUMENT# DOCTYPE
1234567 ABC
1234567 DEF
1234567 GHI
 
if i am reading this correctly, what you have is a temp table and you want to delete all occurances if the same doc# occurs less than 3 times (ie. 1 or 2 times)

therefore you could

delete from #temp where doc# in (select distinct doc# from #temp group by doc# having count(*) < 3)

you might try something like this Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top