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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Where Count(VARIABLE) > 5

Author  Topic 

paull
Yak Posting Veteran

50 Posts

Posted - 2009-08-06 : 12:10:37
Hi guys

I populate a table from a number of other tables to form a "Master_Final" table. I only want records where the count of a particular varible is greater than 5. I am trying to find a way to use either SELECT * WHERE COUNT ...(in the INSERT statement) or DELETE FROM WHERE COUNT ... (after the INSERT) so that only the records I need are actually in the table. I cannot find an example of this being done!!

Any help or advice is much appreciated.

Thanks

P

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-08-06 : 14:11:02
>>where the count of a particular varible is greater than 5

Do you mean that you want only rows where the occurrence of a particular column value exists for at least 5 different rows?
maybe something like this:

select type, name
from sysobjects
where type in (
select type
from sysobjects
group by type
having count(*) >= 5
)
order by type


Be One with the Optimizer
TG
Go to Top of Page

paull
Yak Posting Veteran

50 Posts

Posted - 2009-08-10 : 10:27:24
Hi TG
Sorry for not replying sooner! I tried that and it works perfectly!

Many, many thanks for your help!
Go to Top of Page
   

- Advertisement -