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 |
|
mlevier
Starting Member
33 Posts |
Posted - 2007-09-13 : 15:37:03
|
| I'm trying to delete all records from a table where the count(ANI) > 9. What that means if the ANI shows up more than 9 times I need to get rid of all of them that have the same ANI. I'm using a statement and can't get it to work.deletefrom #feeder03group by anihaving ( count(ani) > 9 )Any help would be great!Thanks in advance! |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-13 : 15:46:08
|
Are you using Microsoft SQL Server?I just wandered because the syntax is so far away... E 12°55'05.25"N 56°04'39.16" |
 |
|
|
mlevier
Starting Member
33 Posts |
Posted - 2007-09-13 : 15:47:23
|
| But then how can I delete them from that select statemnent? |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2007-09-13 : 15:52:19
|
quote: Originally posted by mlevier But then how can I delete them from that select statemnent?
I want you to tell us if that returns anythingIt's like a starting pointWhat's the PK of the table?DELETE ROM #feeder03 oWHERE EXISTS (SELECT ANI FROM #feeder03 iWHERE o.PK = i.PKGROUP BY ANIHAVING COUNT(ANI) > 9)Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
mlevier
Starting Member
33 Posts |
Posted - 2007-09-13 : 15:53:01
|
| Yes, I am working in SQL Server 2005. I got this statement to only select the calls that are greater than 9. I need to know how to delete those records from another table of even delete them from the table that they are in.select Count(#feeder.ani) as callsfrom #feedergroup by ANIhaving ( count(ani) > 9 ) |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-09-13 : 15:53:37
|
[code]DELETE fFROM #Feeder03 AS fINNER JOIN ( SELECT Ani FROM #Feeder03 GROUP BY Ani HAVING COUNT(*) > 9 ) AS u ON u.Ani = f.Ani[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
mlevier
Starting Member
33 Posts |
Posted - 2007-09-13 : 15:59:40
|
| It runs but it doesn't delete them |
 |
|
|
mlevier
Starting Member
33 Posts |
Posted - 2007-09-13 : 16:04:36
|
| Peso - YOU ARE THE MASTER!!! THANKS FOR YOUR HELP!!!!THANKS EVERYONE ELSE FOR THEIR HELP TOO!!! THIS FORUM ROCKS!!! |
 |
|
|
mlevier
Starting Member
33 Posts |
Posted - 2007-09-13 : 16:21:00
|
| Peso - you got it. It was a different way to do it but it works. |
 |
|
|
|
|
|